Code:
#include <stdio.h>
#include <windows.h>
int main(void) {
HKEY hkey;
LONG result_open, result_write, result_close;
printf("Opening Key...\n");
result_open = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
0, KEY_WRITE, &hkey);
if(result_open != ERROR_SUCCESS) {
if(result_open == ERROR_FILE_NOT_FOUND) {
printf("Not found\n");
} else {
printf("Error Opening Key\n");
}
} else {
printf("SUCCESS!!!\n");
}
printf("Writing Value named testval\n");
result_write = RegSetValueEx(hkey, "testval", 0, REG_SZ, "\"C:\\helloworld.exe\"\0", 20);
if(result_write != ERROR_SUCCESS) {
printf("Error Writing Value\n");
} else {
printf("SUCCESS!!!\n");
}
printf("Closing Key...\n");
result_close = RegCloseKey(hkey);
if(result_close != ERROR_SUCCESS) {
printf("Error Closing Key\n");
} else {
printf("SUCCESS!!!!\n");
}
return 0;
}
This one works!
Is there any bad coding practices? Any suggestions (like error checking, I'm really bad at error checking)?
Thanks!