Hi I am trying to create a registry key in C++ but I keep getting the error 5 which googling told me it was access denied but I don’t know to do get the correct privileges. I’m using windows 7 and here’s my code. Thanks
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
LPWSTR szValueBuf = NULL;
char szProductName[MAX_PATH];
LPSECURITY_ATTRIBUTES lpsa;
HKEY hOrchKey;
DWORD dwOpenStatus,
dwType;
char szProuductKey[MAX_PATH];
hr = WcaInitialize(hInstall, "CreateProductKey");
ExitOnFailure(hr, "Failed to initialize");
WcaLog(LOGMSG_STANDARD, "Initialized.");
if (!(lpsa = default_sa()))
return FALSE;
hr = WcaGetProperty(L"PRODUCTNAME",&szValueBuf);
ExitOnFailure(hr, "failed to get Product Name");
wcstombs(szProductName, szValueBuf, 260);
sprintf(szProuductKey,"SOFTWARE\\Company\\%s",szProductName);
// Open the registery Orchestrator key
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
szProuductKey,
0,
"",
REG_OPTION_NON_VOLATILE,
KEY_QUERY_VALUE,
lpsa,
&hOrchKey,
&dwOpenStatus) != ERROR_SUCCESS )
return FALSE;
OS_RegCloseKey(hOrchKey);
return TRUE;
Run as administrator to run it with elevated access.