RegSetValueEx Error 5 (Access Denied)

Aug 29, 2012 at 1:23am
Hello Guys.

I'm im troubles... Every time when i try run this i recive the ERROR 5 RegSetValueEx. When i change HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER and Key adress it works. ¬¬ Some help please?


1
2
3
4
5
6
7
8
9
10
11
HKEY chave;
DWORD disp;
long r = RegCreateKeyEx(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),0, NULL, 0, KEY_SET_VALUE, NULL, &chave, &disp);
printf("CREATE %d\n", r);
r = RegSetValueEx(chave,"xptu",0,REG_SZ,(PBYTE)"Gabriel",(DWORD)7);
printf("Set %d\n", r);
r = RegFlushKey(chave);
printf("Flush %d \n", r);
r = RegCloseKey(chave);
printf("Close %d \n\n\n \n", r);
fflush(stdout);


Thanks all
Aug 30, 2012 at 6:34am
The error means what it says, Access Denied. You don't have write access from your account.
Aug 30, 2012 at 4:09pm
If this is windows 7/8 then it requires administrative privileges. I think you could add shortcuts to startup folder only for current user to launch programs at startup, this does not need admin privileges.,
Last edited on Aug 30, 2012 at 4:11pm
Aug 31, 2012 at 3:04pm
kbw, and modoran. Thanks.

I've solved the problem creating my key on registry in HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE.
Topic archived. No new replies allowed.