TCHAR exepath[MAX_PATH];
GetModuleFileName(0, exepath, MAX_PATH);
    HKEY hKey;
    LONG lnRes = RegOpenKeyEx(
           HKEY_CURRENT_USER,
           "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
           0,KEY_WRITE,
           &hKey
       );
if( ERROR_SUCCESS == lnRes )
{
   lnRes = RegSetValueEx(hKey,
                         "YourProgramsName",
                         0,
                         REG_SZ,
                         exepath,
                         strlen(exepath));
}

To add as a HKLM (For all users) startup item instead of HKCU (Current User), change HKEY_CURRENT_USER to HKEY_LOCAL_MACHINE.

I'm posting this because I had a hard time figuring this out myself, and hopefully this will save some people a lot of searches.


So, if you want your program to startup automatically when the user logs in, just paste this code into it.

Ok.... So instead of making a post that is going to get buried layers deep into the forum... how about you post it as a code snippet?

Oh yes that would probably be better. But I'm not familiar with this forum yet. Could you give me a link to where I should post it? Thanks.

I'm posting this because I had a hard time figuring this out myself, and hopefully this will save some people a lot of searches.

Then you should learn how to use Google Groups.
Adding a program at startup has been posted... 25000 times... for 18 years !

Then you should learn how to use Google Groups.
Adding a program at startup has been posted... 25000 times... for 18 years !

that's not nice..

commented: Useless comment. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.