Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegSetValueEx not working

Status
Not open for further replies.

jsaxon2

Programmer
Oct 24, 2001
56
US
I getting an error "Access Denied" trying to change a value in the resistry. I am logged on a Win2K PC with administrative privleges. What am I doing wrong???

TCHAR szData[80];
sprintf(szData, _T("sa"));

if(m_bprod)
{
HKEY hKey;
if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("Software\\ODBC\\ODBC.INI\\Medsmgrprod"), 0L, KEY_QUERY_VALUE, &hKey))
{
int i = RegSetValueEx(hKey, // subkey handle
"LastUser", // value name
0, // must be zero
REG_SZ, // value type
(LPBYTE)szData, // pointer to value data
lstrlen(szData) + 1); // length of value data

RegCloseKey(hKey);

}

}
 
HKEY_LOCAL_MACHINE requires Adminstrator privledges for writing

-pete

 
I have in the Administrators group. I can change the value using regedit.
 
sorry i missed that in your first post.

KEY_QUERY_VALUE

you need to open the key with more flags than that!

-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top