I have a checkbox on my options dialog that says "Load at start-up", through code, how would i make it so my program would load at the start up of the computer?
Printable View
I have a checkbox on my options dialog that says "Load at start-up", through code, how would i make it so my program would load at the start up of the computer?
Put it in the Registry:
Code:HKEY hRegistryKey;
char *sBuffer;
sBuffer = "C:\\pathofyourexe";
RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Currentversion\\run", 0, NULL, 0, KEY_WRITE, NULL, &hRegistryKey, NULL);
RegSetValueEx(hRegistryKey, "PSL", 0, REG_SZ, (LPBYTE)sBuffer, strlen(sBuffer)+1);
I know nothing about the registry, so is that the exact code to make the app start at the start up of the comp? And if it is, could you post the code to make it not start up at the start up of the comp, thanks.
To set the value from the registry use:
To delete the value from the registry use:Code:HKEY hRegistryKey;
char *sBuffer;
sBuffer = "C:\\pathofyourexe";
RegCreateKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\Currentversion\\run", 0, NULL, 0, KEY_WRITE, NULL, &hRegistryKey, NULL);
//To set The value(load it on start up)
RegSetValueEx(hRegistryKey, "SomeName", 0, REG_SZ, (LPBYTE)sBuffer, strlen(sBuffer)+1);
Code://To delete the value(not load it at start up)
RegDeleteValue( hRegistryKey,"SomeName");
You can get the location of your exe in other ways:
Code:char exepath[xx] = "\\nameofyourfile.exe";
TCHAR buff[256];
GetCurrentDirectory(256,buff);
strcat(buff,pateka);
//buff contains the path of your exe