Reputation: 319
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 = RegCreateKeyEx( 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.
Upvotes: 1
Views: 2723
Reputation: 24457
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
Upvotes: 0
Reputation: 613302
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:
HKEY_LOCAL_MACHINE
.HKEY_LOCAL_MACHINE
.Of these options the first is by far to be preferred.
Upvotes: 4