Hello,
I have been trying to write a simple program that will read and edit the registry. It seems to open the keys fine, but then when it goes to write, nothing is written in the registry. The program is run as administrator, so it isn't a lack of privilege.
The purpose of the program is to setup automatic logon for an account on multiple computers (the multiple computers part is already handled elsewhere). The values are going to be reset (set to empty strings) when work on the computers is done, and then rebooted to remove the automatic logon. However, I am having trouble reading (which I pretty much gave up on doing, since it's not
required) and writing. I receive no error attempting to open the registry key.
The code I'm attempting to use:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <windows.h>
#include <malloc.h>
#include <stdio.h>
int main(int argc, char* argv[]){
if(argc < 2){
printf("Usage: %s on/off [username] [password] [domain]", argv[0]);
return 1;
}
int ecode = 0;
HKEY hkey = 0;
LPCTSTR skey = TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon");
if((ecode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, // HKEY
skey, // Sub Key
0, // reserved
KEY_ALL_ACCESS, // Access flags
&hkey)) != ERROR_SUCCESS){ // Returned HKEY
printf("Error opening registry key: %i\n", ecode);
return 1;
}
LPCTSTR data = TEXT("Data\0");
int length = (strlen(data)*sizeof(LPCTSTR));
if((ecode = RegSetValueEx(hkey, // Returned HKEY
TEXT("DefaultPassword"), // Value
0, // Reserved
REG_SZ, // Type
(LPBYTE)data, // Data
length)) != ERROR_SUCCESS){ // Size of data
printf("Error setting value: %i", ecode);
return 2;
}
if(argv[1] == "on"){
} else if(argv[1] == "off"){
}
}
|
There are no errors on opening nor editing the registry, yet when I refresh regedit, there is no change.
This compiles fine on CodeBlocks 13.12, and I have tried adding '-ladvapi32' to the build options for the project.
Any help to solve my issue is greatly appreciate,
~ Zalerinian