I want to change a few settings of a Windows user that I created in my application. If I understand correctly, his "HKEY_CURRENT_USER
" values will be under HKEY_USERS/<sid>/...
. Is this correct? How can I get the sid of the user, if I know the user name and the domain?
Edit: How can I correctly edit the HKCU keys of that user, if I have the sid already?
In Registry Editor, right-click the key that you can't edit (or the key that contains the value you can't edit) and then choose “Permissions” from the context menu. In the Permissions window that appears, click the “Advanced” button. Next, you're going to take ownership of the Registry key.
The HKEY_CURRENT_USER registry hive is specific to each user, so in order to modify this for another user, we first need to identify where that information is stored.
I have a program that does exactly that. Here is the relevant part of the code:
NTAccount ntuser = new NTAccount(strUser);
SecurityIdentifier sID = (SecurityIdentifier) ntuser.Translate(typeof(SecurityIdentifier));
strSID = sID.ToString();
You will need to import two namespaces:
using System.DirectoryServices;
using System.Security.Principal;
Hope this helps.
Then use Registry.Users.SetValue
with SID string\path to set the registry value.
This might not work as intended if you are editing a logged-off profile, especially a roaming profile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With