Adding a key to other users in the registry using an administrator account

How to add a new key to the registry of other users using C # (or c / C ++ or another language)

here is the scenario: Client PC: Administrator account (authorized)

User "A" and "User B" can access the client PC only through the domain "myDomain" (they are already logged in once and have their own folder for the user of the client PC)

so I ran this code to create a new key using admin

Registry.CurrentUser.CreateSubKey (@ "SOFTWARE \ MyProgram \ DefaultConfig");

but the problem is that this key is only created for the Administrator account

I want to create this key for "User A" and "User B" also when using the "Administrator" account

both users "A" and "User B" are not displayed in HKEY_USERS

And if there are more users on one PC, I want to add this registry key to them, is it also possible to code a code that adds a key for all users? Read and write cycle?

+4
source share
1 answer

The keys for all users are stored under the root key HKEY_USERS . Under this root key there is a key for each user who has a SID as the key name.

You need to get the SID of the desired user, then access this root key:

 // Gets the SID of the desired user NTAccount f = new NTAccount(userName); SecurityIdentifier s = (SecurityIdentifier)f.Translate(typeof(SecurityIdentifier)); string sid = s.ToString(); // Now you can access to the HKEY_USERS root key string path = @"SOFTWARE\Console\DefaultConfig"; Registry.Users.CreateSubKey(string.Format("{0}\\{1}", sid, path)); 

But to be honest, I'm not sure if this is a very good idea. Could you use Registry.LocalMachine instead, which applies to all users?

+3
source

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


All Articles