creating a Registry key

Hey I want to create a new key in

HKEY_LOCAL_MACHINE,"Software\\Microsoft\\Windows\\CurrentVersion\\Run

I tried the below codes but they didn't work

int main()
{

HKEY hKey;
DWORD disp ;
DWORD createError = RegCreateKeyEx(
HKEY_LOCAL_MACHINE, // handle of an open key
"Software\\Microsoft\\Windows\\CurrentVersion\\Run", // subkey name
0, // reserved
NULL, // class string
REG_OPTION_NON_VOLATILE, // permanent entry
KEY_READ | KEY_WRITE, // desired security access
NULL, // security attributes (default)
&hKey, // handle for opened key returned
&disp ) ; // created new vs. opened existing
if ( createError == ERROR_SUCCESS )
{
// now can use hKey in other APIs
}
else
{
// createError is an error code which can be looked up
// in WINERROR.H or fed into FormatMessage.
}
//directory of your exe file.
RegSetValueEx(hKey, "hello world",0,REG_SZ,PathToFile,sizeof(PathToFile));


//Close key.
RegCloseKey(hKey);



return 0;
}

but it didn't seem to work .
any idea were it went wrong ?
or any code to create a new key ?
thnk for help in advance
Last edited on
It requires administrator priveleges to write in that location. If you get ERROR_ACCESS_DENIED then this is the cause.
Topic archived. No new replies allowed.