I am trying to add an application to run on startup in Windows. I am using RegSetValueEx() to do this:
1 2 3 4 5 6 7 8 9 10 11 12
int main()
{
HKEY hkey;
long regOpenResult;
constchar path[]="C:\\Users\\Gizda\\Documents\\Visual Studio 2010\\Projects\\stuffs\\Debug\\stuffs.exe";
regOpenResult = RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS, &hkey);
LPCSTR stuff = "stuffs";
RegSetValueEx(hkey,stuff,0,REG_SZ,(BYTE*) path, strlen(path));
RegCloseKey(hkey);
return 0;
}
When I compile the code above, it runs fine, does not give any error. When I check for the return value of both ReturnOpenKeyEx and RegSetValueEx, they return ERROR_SUCCESS. But the key is not placed in the registry. Any ideas?