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.
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