Solved

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

Posted on 1998-10-01
3
227 Views
Last Modified: 2010-04-01
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?
0
Comment
Question by:afalvey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:afalvey
ID: 1174152
Bye the way.  The code is written in VC++ 5.0 and we are using the following APIs for accessing the system registry:

RegOpenKey
RegEnumVal
RegCloseKey
RegQueryValueEx
RegQueryInfoKey
RegSetValueEx
RegFlushKey
0
 
LVL 32

Accepted Solution

by:
jhance earned 100 total points
ID: 1174153
Under NT, each registry key can have protections set.  When you use RegOpenKeyEx, the samDesired parameter to the function specified what type of access to the key you want.  (Under Win9X, this parameter is ignored)  If you don't have rights to this key you will get an error returned from the function.  There is no workaround, this is the way NT is designed.  You either need to relax the security on the keys in question or logon to the system with an account having the correct privileges.
0
 

Expert Comment

by:tsollas
ID: 1174154
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question