afalvey
asked on
NT/95 Registry: I can't read/write to the registry in my code when the NT/95 system is locked down or the user doesn't have admin rights
I am making updates to the system registry but when the 95/NT system I am testing on is locked down or the user I am logged in as doesn't have adminstrative rights I get a fatal error stating that I cannot access the registry. Does anyone know of a workaround for this? Are there areas in the registry that cannot be read or written to if the system is locked down or the user doesn't have administrative rights?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
jhance is not entirely correct. You can get around this, but you'll have to use impersonation. It basically looks like this:
HANDLE hToken;
LogonUser( szUser, szDomain, szPassword, LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &hToken ););
ImpersonateLoggedOnUser( hToken );
// do stuff
CloseHandle( hToken );
RevertToSelf();
What this does is a) log on as a specific user. You'll want to log in as a user with sufficient rights and then b) tells your current thread to "impersonate" the token of the logged in user. The user logged in needs to have the SE_TCB_NAME privilege enabled. This means, of course, you'll have to either prompt the user for an appropriate user account, or you'll have to store that somewhere so you can use it behind the scenes.
Supposedly there's a way to impersonate explorer (if I recall, its security context is the system account), and I think it involves getting Explorer's process token and impersonating that, but I haven't tried it.
HANDLE hToken;
LogonUser( szUser, szDomain, szPassword, LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &hToken ););
ImpersonateLoggedOnUser( hToken );
// do stuff
CloseHandle( hToken );
RevertToSelf();
What this does is a) log on as a specific user. You'll want to log in as a user with sufficient rights and then b) tells your current thread to "impersonate" the token of the logged in user. The user logged in needs to have the SE_TCB_NAME privilege enabled. This means, of course, you'll have to either prompt the user for an appropriate user account, or you'll have to store that somewhere so you can use it behind the scenes.
Supposedly there's a way to impersonate explorer (if I recall, its security context is the system account), and I think it involves getting Explorer's process token and impersonating that, but I haven't tried it.
ASKER
RegOpenKey
RegEnumVal
RegCloseKey
RegQueryValueEx
RegQueryInfoKey
RegSetValueEx
RegFlushKey