A 32-bit Windows service entry in the 64-bit registry. (AutoAdminLogon keys)

// Edit: Wow. It’s strange that I’ve been working on this all day and just realized what I need to do:

key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); 

And then it worked. I did not know that you should have done this. Thanks to all who responded. I just messed around and looked for my key and noticed that it was placed in the wrong place.

// Original question:

I have not seen a working solution for this, and I'm not sure if this is a mistake.

I have a 32-bit Windows C # service running on a 64-bit version of Windows 7. My goal is to write to the 64-bit registry, not to the Wow6432Node subkey, because for AutoAdminLogon, the 64-bit system does not seem to check the 32-bit kind of keys.

So my code is as follows:

 static public void LoginAsGuest(EventLog eventLogger) { RegistrySecurity userSecurity = new RegistrySecurity(); RegistryAccessRule userRule = new RegistryAccessRule("Everyone", RegistryRights.FullControl, AccessControlType.Allow); userSecurity.AddAccessRule(userRule); var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", RegistryKeyPermissionCheck.ReadWriteSubTree); if (key == null) { eventLogger.WriteEntry("Error accessing the registry key"); } else { try { key.SetValue("AutoAdminLogon", "1", RegistryValueKind.String); key.SetValue("DefaultUserName", "guest", RegistryValueKind.String); key.SetValue("DefaultPassword", "password", RegistryValueKind.String); } catch (Exception exception) { eventLogger.WriteEntry("Problem setting up keys: " + exception); } } key.Close(); Reboot(); } 

An exception or error is not thrown. Nothing is written to the registry in a 32-bit or 64-bit representation. I tried using:

 key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); 

But he has the same result. Now, if I just write without any representation, my program will successfully write to the subsection:

 SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon 

Basically all I want is to write in a subsection:

 SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon 

Does anyone know why the above code does not record the requested key? (I will point out that AutoAdminLogon and two other keys are used by default by the Windows credential provider, so when it starts Windows it checks these keys, and if AutoAdminLogon is set to 1, it will automatically register with the specified username and password. M do this, so that the computer can be registered as a guest by installing the keys and then restarting the computer).

+6
source share
1 answer

It’s strange that I’ve been working on this all day and just realized what I need to do:

 key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true); 

And then it worked. I did not know that you should have done this. Thanks to all who responded. I just messed around and looked for my key and noticed that it was placed in the wrong place.

+2
source

Source: https://habr.com/ru/post/911344/


All Articles