There have different applications and Services in our PCs run automatically on system startup. How shall we add our application to this list?
Actually windows knows what to run at startup by keeping a list of applications name and paths under the following registry path, HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run. We can either manually add application name and path to that registry location or can do the same by following Windows APIs RegOpenKeyEx and RegSetValue.
void RunApplicationOnStartup(CString strApplicationPath, CString strKeyName) { HKEY hKey; CString sKeyName; unsigned char szFilePath[100]; /** Open Run Registry location */ LONG lnRes = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0L,KEY_WRITE, &hKey ); lstrcpy((char *) szFilePath , LPCTSTR(strApplicationPath)); if (ERROR_SUCCESS == lnRes) { /** Set full application path with a keyname to registry */ lnRes = RegSetValueEx(hKey, LPCTSTR( sKeyName ), 0, REG_SZ, szFilePath, REG_SZ ); if( ERROR_SUCCESS == lnRes ) AfxMessageBox(_T("Set at startup has done successfully")); else AfxMessageBox(_T("Failed to set at startup"); } else { AfxMessageBox(_T("Failed to set at startup")); } }
If you create it under HKEY_LOCAL_MACHINE, it will apply to all users of the machine. If you create it under HKEY_CURRENT_USER, then the program will run automatically upon startup only for that user.
Hi Sanoop,
I am badri, doing B.Tech Final year in chennai. Me and my friend doing project on “Detecting trojans on behaviour analysis”. Trojans uses API calls to conceal and to modify the registry, those API calls are in VC++ . I don’t have enough knowlege in vc++. we need your assistance , I need your mail address to ask doubts.
Thank you.
Hello Badri,
You can catch me on my personal mail id sanoop.sp@gmail.com
It’s my pleasure to help you if I can….
Thanks,
Sanoop
I am glad to be a visitant of this utter blog, thanks for this rare information!
Thanks a lot for your comment 🙂