RegSetValueEx

E

elitecodex

Hey everyone. I have a function that reads in a registry value (for
the windows firewall) and one that disables it.

Reading the value works perfectly. However, I am getting an access
denied error when trying to set the value. Here is the body of the
function

HKEY hkeyFirewall;

if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, registryLocations[0], 0,
KEY_WRITE | KEY_READ, &hkeyFirewall) != ERROR_SUCCESS)
wxLogError("FAILED - Could not open the firewall policy registry
entry");
else
{
if ( RegSetValueEx(hkeyFirewall, "EnableFirewall", 0, REG_DWORD,
(BYTE*)0, sizeof(DWORD)) != ERROR_SUCCESS )
{
ErrorString("DisableWindowsFirewall()");
wxLogError("FAILED - Could not set the EnableFirewall value");
}
RegCloseKey(hkeyFirewall);
}


The error is in RegSetValue. It returns "Access denied". ErrorString
is almost taken completely out of the PlatformSDK which is how Im
getting the error.

I've also tried opening the key with KEY_ALL_ACCESS and KEY_SET_VALUE
in combination with KEY_WRITE | KEY_READ as you see above.

Any ideas? The user is in the Administrator group. Thanks!
 
B

Bruno van Dooren

if ( RegSetValueEx(hkeyFirewall, "EnableFirewall", 0, REG_DWORD,
(BYTE*)0, sizeof(DWORD)) != ERROR_SUCCESS )

(BYTE*)0

is wrong. you are supposed to supply a pointer to a variable that contains
the data.
you supply a pointer with value 0, i.e. you supply a NULL pointer.

do something like this

DWORD val = 0;
if ( RegSetValueEx(hkeyFirewall, "EnableFirewall", 0, REG_DWORD,
(BYTE*)&val, sizeof(DWORD)) != ERROR_SUCCESS )

Though why this triggers an access denied error i don't know.
my first guess was that your program is not running with admin credentials,
but apparently you already thought of that.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 
E

elitecodex

Bruno said:
(BYTE*)0

is wrong. you are supposed to supply a pointer to a variable that contains
the data.
you supply a pointer with value 0, i.e. you supply a NULL pointer.

do something like this

DWORD val = 0;
if ( RegSetValueEx(hkeyFirewall, "EnableFirewall", 0, REG_DWORD,
(BYTE*)&val, sizeof(DWORD)) != ERROR_SUCCESS )

Though why this triggers an access denied error i don't know.
my first guess was that your program is not running with admin credentials,
but apparently you already thought of that.

--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"

I tried it like that and to no avail... same results. Here is the
updated copy:

DWORD value = 0;
if ( RegSetValueEx(hkeyFirewall, "EnableFirewall", 0, REG_DWORD,
(LPBYTE) &value, sizeof(DWORD)) != ERROR_SUCCESS )

Any other ideas? Am I the only one with this issue?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top