I want to add my program to autorun. I know there is a registry key for it that doesnt require admin rigths to edit it.
It's
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run.
I'm using unicode bild. I wrote a function that is for adding program to autorn.
void AddToRegAutorun(const std::wstring& _valueName, const std::wstring& _path)
{
HKEY hkey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Run"), 0, /*KEY_SET_VALUE*//*MAXIMUM_ALLOWED*/KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS)
RegSetValueEx(hkey, _valueName.c_str(), 0, REG_SZ, (LPBYTE)_path.c_str(), ((DWORD)wcslen(_path.c_str()) + 1)* sizeof(wchar_t));
RegCloseKey(hkey);
}
RegOpenKeyEx()
returns ERROR_SUCCESS.
But RegSetValueEx()
returns 5
(ERROR_ACCESS_DENIED).
Any suggestions?