我想更改我在应用程序中创build的Windows用户的一些设置。 如果我理解正确,他的“ HKEY_CURRENT_USER ”值将在HKEY_USERS/<sid>/... 。 它是否正确? 如果我知道用户名和域,我怎样才能得到用户的sid?
编辑:我如何正确编辑该用户的HKCU密钥,如果我已经sid?
Windows服务挂起在启动过程中启动
将string转换为浮点并格式化(C#)
如何从驱动器的全名获取驱动器号
如何使用SPI_SETWORKAREA标志调整桌面工作区的大小?
Subversion在哪里保存?
NTAccount ntuser = new NTAccount(strUser); SecurityIdentifier sID = (SecurityIdentifier) ntuser.Translate(typeof(SecurityIdentifier)); strSID = sID.ToString();
您将需要导入两个名称空间:
using System.DirectoryServices; using System.Security.Principal;
希望这可以帮助。
然后使用Registry.Users.SetValue和SID字符串 path来设置注册表值。
如果您正在编辑已注销的配置文件(尤其是漫游配置文件),则这可能无法正常工作。
这有两个步骤。 首先你必须得到用户sid。 其次,您必须加载用户注册表配置单元。 其他用户配置单元默认情况下不加载,因此您必须明确加载它。
要加载用户的注册表配置单元,请通过pinvoke使用LoadUserProfile Windows API。 有一个补充UnloadUserProfile卸载配置单元,当你完成它。
您可以按示例使用查询,并使用PrincipalSearcher搜索相应的UserPrincipal
// Since you kNow the domain and user PrincipalContext context = new PrincipalContext(ContextType.Domain); // Create the principal user object from the context UserPrincipal usr = new UserPrincipal(context); usr .Givenname = "Jim"; usr .Surname = "Daly"; // Create a PrincipalSearcher object. PrincipalSearcher ps = new PrincipalSearcher(usr); PrincipalSearchResult<Principal> results = ps.FindAll(); foreach (UserPrincipal user in results) { if(user.displayName == userName) { var useRSSid = user.Sid.ToString(); } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。