I really need your help. I tried everything but the result is always the same, nothing. Please advise.
And this is my code
#include <windows.h>
#include <iostream>
#include <windef.h>
using namespace std;
int main (void)
{
HKEY hKey;
LONG regOpenResult;
const char PATH[] = "C:\\Users\\les\\Documents\\visual studio 2010\\Projects\\registryTester\\Debug\\registryTester.exe";
RegCreateKeyExW(HKEY_LOCAL_MACHINE,
L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
0,
NULL,REG_OPTION_VOLATILE,
KEY_SET_VALUE,
NULL,
&hKey,
NULL
);
RegSetValueExW(hKey, L"regTest", 0, REG_SZ, (BYTE*)PATH, strlen(PATH));
RegCloseKey(hKey);
}
Check the return status of each API call!!!! Use GetLastError () for each failure.
Knowing the error should lead you to resolve the problem.
Otherwise, you’re flying completely blind…
Yes, PATH shouldn’t be an 8-bit character string if you’re calling a 16-bit Unicode API. But it’s not necessarily the only problem.
And yes, “permissions” could very definitely be an issue if you’re using Vista, Windows 7 or higher.