#include <windows.h>
#include <stdio.h>
BOOL WriteReg( HKEY key, char *place, char *name, char *Value )
{
HKEY hkey;
if( (RegOpenKeyEx(key, place,0, KEY_ALL_ACCESS,&hkey)) != ERROR_SUCCESS )
return FALSE;
if( (RegSetValueEx(hkey, name, 0, REG_SZ, (BYTE *)Value, strlen(Value))) != ERROR_SUCCESS )
return FALSE;
if( (RegCloseKey(hkey)) != ERROR_SUCCESS )
return FALSE;
return TRUE;
}
BOOL DeleteReg( HKEY key, char *place, char *name )
{
HKEY hKey;
if( (RegOpenKeyEx(key, place,0, KEY_ALL_ACCESS,&hKey)) != ERROR_SUCCESS )
return FALSE;
if( (RegDeleteValue(hKey, name)) != ERROR_SUCCESS )
return FALSE;
if( (RegCloseKey(hKey)) != ERROR_SUCCESS )
return FALSE;
return TRUE;
}
int main()
{
HKEY KEY = HKEY_LOCAL_MACHINE;
char place[] = {"Software\\Microsoft\\Windows\\CurrentVersion\\Run"};
char name[] = {"Notepad"};
char Value[] = {"C:\\WINDOWS\\notepad.exe"};
BOOL WriteSuccess;
BOOL DeleteSuccess;
printf("Writing to registry . . .\n\n");
WriteSuccess = WriteReg( KEY, place, name, Value );
if( WriteSuccess == TRUE )
printf("NO ERRORS OCCURRED!\n");
else
printf("AN UNKNOWN ERROR OCCURRED!\n");
printf("\nDeleting from registry . . .\n\n");
DeleteSuccess = DeleteReg( KEY, place, name );
if( DeleteSuccess == TRUE )
printf("NO ERRORS OCCURRED!\n");
else
printf("AN UNKNOWN ERROR OCCURRED!\n");
return 0;
}