开发者

Unable to write in registry when windows UAC is set to always notify

开发者 https://www.devze.com 2023-03-06 16:55 出处:网络
I have a C++ application, In which we write settings to the registry (Under HKEY_CURRENT_USER & HKEY_LOCAL_MACHINE for my application).When windows User Access Control is set to Always Notify, Reg

I have a C++ application, In which we write settings to the registry (Under HKEY_CURRENT_USER & HKEY_LOCAL_MACHINE for my application).When windows User Access Control is set to Always Notify, RegCreateKeyEx method returns access denied and it does not write to HKEY_LOCAL_MACHINE but it writes successfully in HKEY_CURRENT_USER registry. I am using this method to write:

lRet = RegCre开发者_JAVA技巧ateKeyEx( m_hSWRootKey, LPCTSTR(strKey), 
0, _T(""), m_dwCreationFlag, KEY_WRITE | KEY_READ, 
NULL, &hKey, &Disposition );

This method works fine when UAC is set to Never Notify.

What is the reason that it does not write to HKEY_LOCAL_MACHINE? How can i override the windows UAC setting so i will be able to write when it is set to Always Notify?

Please suggest.


You can't write to HKEY_LOCAL_MACHINE unless you have administrator rights. That has always been true for Windows versions based on NT. What changes with UAC is that the admin users run with a standard user token by default and only elevate to gain admin rights for operations that need elevated rights.

You have two options:

  1. Find a way to achieve your goals without writing to HKEY_LOCAL_MACHINE.
  2. Require that the user obtains admin rights for the portions of the app that write to HKEY_LOCAL_MACHINE.

Of these options the first is by far to be preferred.


If you do take the path to only allow the application to be run as admin, you can set the manifest in Visual Studio in:

Project >> Properties >> Configuration Properties >> Linker >> Manifest File >> UAC Execution Level.

Ideally you would find some way that does not require modifying HKEY_LOCAL_MACHINE

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号