c++ isn't Inserting values into registry -
my test program insert values registry not work. have not found solution on google or website. after running program administrator, instantly closes , register not modified.
hkey hkey; const char path[] = "c:\\program files\\windows nt\\accessories\\wordpad.exe"; regopenkeyex(hkey_local_machine, "software\\microsoft\\windows\\currentversion\\run", 0, key_write, &hkey); regsetvalueex(hkey, "testwordpad", 0, reg_sz, (byte*)path, strlen(path)); regclosekey(hkey); return 0;
after start debugging in output:
'consoleapplication1.exe' (win32): loaded 'c:\users\jakub\desktop\consoleapplication1\debug\consoleapplication1.exe'. symbols loaded. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\ntdll.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\kernel32.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\kernelbase.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\advapi32.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\msvcrt.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\sechost.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\rpcrt4.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\sspicli.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\cryptbase.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\vcruntime140d.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\ucrtbased.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-timezone-l1-1-0.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-file-l2-1-0.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-localization-l1-2-0.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-synch-l1-2-0.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-processthreads-l1-1-1.dll'. cannot find or open pdb file. 'consoleapplication1.exe' (win32): loaded 'c:\windows\syswow64\api-ms-win-core-file-l1-2-0.dll'. cannot find or open pdb file. program '[3052] consoleapplication1.exe' has exited code 0 (0x0).
there 2 reasons code won't work consistently:
if run on windows vista or later requires admin rights (e.g. elevated uac) write hklm. can try launching admin command prompt or running visual studio administrator
if code compiled 32-bit app run on 64-bit system modifies following key:
hkey_local_machine\software\wow6432node\microsoft\windows\currentversion\run
if take these 2 points account code does work. recommend checking return codes each function. instance:
long lresult=regopenkeyex(hkey_local_machine, "software\\microsoft\\windows\\currentversion\\run", 0, key_write, &hkey);
if run code without admin rights find returns 5 (error_access_denied).
Comments
Post a Comment