I'm writing a console app which accesses and changes some values under
Windows registry: HKLM\System\CurrentControlSet\Enum and I'm the admin on
the machine (XP).
I have done the following steps but failed at step #4 with access denied
error.
1. Get the process handle with PROCESS_ALL_ACCESS; success.
2. Get the token handle with TOKEN_ALL_ACCESS; success.
3. Adjust token privilege to SE_TAKE_OWNERSHIP_NAME; success.
4. open the reg key "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Enum" using
RegOpenKeyEx with KEY_ALL_ACCESS (tried also WRITE_ONWER); but failed with
return code 5 (Access Denied).
If I manually change the permission for "EVERYONE" with full permissions
using RegEdit.exe, it worked fine. But this is not what I want. I like the
app to be able to programmatically do that through certain steps (hopefully
similar steps to what I have tried above).
Any pointer on the possible cause is appreciated.
Thanks in Advance.
Polaris
HKLM is not accessible to a non-elevated process under Vista or Windows 7.
If your application had no manifest, then writing would to HKLM would be
virtualized, so I assume that your application has the standard "AsInvoker"
manifest (as it should).
Really, your application should not be writing to HKLM. If you need occasional
access to HKLM is perform some specific task, you could instruct the user to
start the application as Administrator.
--
David Wilkinson
Visual C++ MVP
"David Wilkinson" <no-r...@effisols.com> wrote in message
news:u%2352UA3a...@TK2MSFTNGP02.phx.gbl...
> Polaris wrote:
>> I'm writing a console app which accesses and changes some values under
>> Windows registry: HKLM\System\CurrentControlSet\Enum and I'm the admin on
>> the machine (XP).
>
--pa
"Polaris" <etpo...@hotmail.com> wrote in message
news:e8crIm0a...@TK2MSFTNGP02.phx.gbl...
Oops, yes. I missed the XP (and the particular reference to the Enum registry
key). In short, I did not read the question carefully...
I would still maintain, though, that an application has no business messing with
anything in HKLM. This was possible in XP because most users run as
administrator, but in Vista/Win7 it is not possible without elevation.