helping with registry

this program should make the hibernate off ;
but i dont know what is the problem of my program !
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
38
39
40
41

#include <windows.h>
#include <iostream>
#include "string.h"
using namespace std;

int main ()
{ 
HKEY hKey;
LPCTSTR sk = TEXT("SYSTEM\\CurrentControlSet\\Control\\Power");

LONG openRes = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sk, 0, KEY_ALL_ACCESS , &hKey);

if (openRes==ERROR_SUCCESS) {
    printf("Success opening key.");
} else {
    printf("Error opening key.");
}

LPCTSTR value = TEXT("HiberFileSizePercent");
LPCTSTR data = L"1\0";

LONG setRes = RegSetValueEx (hKey, value, 0, REG_DWORD, (LPBYTE)data, sizeof data);
if (setRes == ERROR_SUCCESS) 
{
	printf("Success writing to Registry.");
} 
else
{
    printf("Error writing to Registry.");
}
cout << setRes << endl;

LONG closeOut = RegCloseKey(hKey);
if (closeOut == ERROR_SUCCESS) {
    printf("Success closing key.");
} else {
    printf("Error closing key.");
}
cin.get();
}

Are we getting an error when you try to compile? If so then what might that error be?

What version of Windows are you running this on? Might UAC or Registry Virtualization be the cause of your problem?

Some of these registry keys are only read when the system starts up. Have you tried to reboot?

You seem to be testing the return values for success but you're not making any calls to "FormatMessage()" to resolve any error codes on failure, why is that?
Topic archived. No new replies allowed.