How to run an Application on windows start up

24 12 2009



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,  
                  &hKey ); 
      lstrcpy((char *) szFilePath , LPCTSTR(strApplicationPath));
      if (ERROR_SUCCESS == lnRes)
      /** Set full application path with a keyname to registry */
      lnRes = RegSetValueEx(hKey,
                  LPCTSTR( sKeyName ),
                  REG_SZ ); 
      if( ERROR_SUCCESS == lnRes )
         AfxMessageBox(_T("Set at startup has done successfully"));
         AfxMessageBox(_T("Failed to set at startup");
      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.




4 responses

26 12 2009

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.

27 12 2009
Sanoop S P

Hello Badri,

You can catch me on my personal mail id
It’s my pleasure to help you if I can….


19 03 2012

I am glad to be a visitant of this utter blog, thanks for this rare information!

20 03 2012
Sanoop S P

Thanks a lot for your comment 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: