Date: 02-16-2022
Return to Index
created by gbSnippets
Programs can be loaded and run via entries in the Registry. You
can also include them in your Startup Folder. In fact, you have
multiple Startup Folders, one for you, one for the default user,
one for all users, and of course one for each of the other users
on your PC. So depending upon who logs in, which Startup folder(s)
are used.
http://www.codeguru.com/cpp/w-p/system/registry/article.php/c5677/Run-At-Startup-Programmatically.htm
You can use this code to let your program run automatically at system startup,
it shows you also how to use some of API registry functions. Before you start
you must know that Windows knows what to run at startup by keeping a list of
's name and pathes under the following Key in the system registry:
HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run.
All that you will do now is to add our 's path and name in this key by
using "RegOpenKeyEx" and "RegSetValue" API registry functions. The algorithm is so simple:
FIRST : Open the "Run" key.
SECOND: Set it with new value ('s path and name.)
Here is the source code:
LONG lnRes = RegOpenKeyEx(
HKEY_LOCAL_MACHINE, // handle of open key
// The following is the address of name of subkey to open
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0L,KEY_WRITE,
&hKey // address of handle of open key
);
// now add program path to the RUN key
lstrcpy( (char *) szFilePath , LPCTSTR(m_strFileName) );
GetDlgItemText( IDC_KEYNAME, sKeyName ); //Get value name
if( ERROR_SUCCESS == lnRes )
{
lnRes = RegSetValueEx(hKey,
LPCTSTR( sKeyName ), // handle of the opened
// key to set value for
0,
REG_SZ,
szFilePath, //value data
REG_SZ );
'gbs_01209
'Date: 05-11-2013
http://www.garybeene.com/sw/gbsnippets.htm