473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 2196
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Lauren Quantrell | last post by:
Maybe a dumb question - I'm new to ODBC. How do I install an Access ..mde file on a user's workstation and create the ODBC connection to the backend SQL Server database without having to go through...
1
by: Dan | last post by:
Hi I have recently converted an Access 97 database to 2003. Most of the change went fine with no problems but every now and then my DSN connections to my back-end SQL-database fail and it does not...
1
by: Dan | last post by:
Hi I have recently converted an Access 97 database to 2003. Most of the change went fine with no problems but every now and then my DSN connections to my back-end SQL-database fail and it does not...
5
by: Alec | last post by:
Hi All, I am currently trying to link in Access 97 to a table in a MSSQL 7 server. Initially the link is fine, however, when I close the access database and re-open it from the same network...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.