Cannot write to registry under HKEY_LOCAL_MACHINE \ Software

I am writing an application that should create a special user account hidden from the login screens and the applet of the control panel users. By writing a DWORD value of 0 with the username in the registry key below, I can perform this task:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon \ SpecialAccounts \ UserList

The problem is that on Windows 7 with UAC, no matter what I try, I cannot programmatically write the value for the key above.

I understand that writing to specific keys is not allowed on Windows 7 with UAC unless you use Administrative privileges. I added the application manifest requestedExecutionLevel level="requireAdministrator" uiAccess="false" , I accept the UAC prompt when my program is running, my account is a member of the Administrators, but I still can not write this registry key.

What else do I need to do? How can I write keys and values โ€‹โ€‹in HKEY_LOCAL_MACHINE\SOFTWARE in any application configuration?

Additional information ... When my program starts, there are no errors, and it seems that they write values. I assume Windows is virtualizing the location I'm writing to. I need to write the actual location, not virtual, if I want to hide this special user account.

+7
source share
4 answers

Perhaps the program works as a 32-bit program in a 64-bit operating system? In case I recommend you look for the values โ€‹โ€‹created in the Wow6432Node section HKEY_LOCAL_MACHINE\SOFTWARE .

Read more about such virtualization here . You can use the KEY_WOW64_32KEY flag in some APIs to be able to work with the full registry without virtualization.

+12
source

Writing a value to the registry

 string user = Environment.UserDomainName + "\\" + Environment.UserName; RegistrySecurity rs = new RegistrySecurity(); rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.WriteKey | RegistryRights.ChangePermissions, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Deny)); RegistryKey rk = null; try { rk = Registry.CurrentUser.CreateSubKey("SOFTWARE\\TEST", RegistryKeyPermissionCheck.Default, rs); rk.SetValue("NAME", "IROSH); rk.SetValue("FROM", "SRI LANKA"); } 
+1
source

This may have something to do with the redirection they added in Vista. I would be curious if you tried to read this registry value from your code, if you returned the value that you expected. You can also run RegMon to find out if you can redirect redirection.

0
source
 RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",true); rk.SetValue("Name", "Value"); 
0
source

All Articles