468,249 Members | 1,470 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

RegSetValueEx

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!

Jul 11 '06 #1
2 2047
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
br**********************@hotmail.com
Remove only "_nos_pam"
Jul 11 '06 #2

Bruno van Dooren wrote:
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
br**********************@hotmail.com
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?

Jul 12 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.