C# 获取所有管理员的桌面路径
我需要为系统中的所有管理员创建应用程序的桌面快捷方式。 我正在使用以下代码来获取用户列表。
var identifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
GroupPrincipal group = GroupPrincipal.FindByIdentity(new PrincipalContext(ContextType.Machine), identifier.Value);
foreach (Principal principal in group.Members)
{
Console.WriteLine(principal.Name);
}
我需要以某种方式获取每个用户的桌面路径。你能给我建议解决方案吗?非常感谢。
I need to create desktop shortcuts to my app for all administratos in the system.
I'm using the following code to get user list.
var identifier = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
GroupPrincipal group = GroupPrincipal.FindByIdentity(new PrincipalContext(ContextType.Machine), identifier.Value);
foreach (Principal principal in group.Members)
{
Console.WriteLine(principal.Name);
}
I need somehow to get desktop path for each user. Could you suggest me solution? Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要调用 SHGetFolderLocation 函数 (http://msdn.microsoft.com/en-us/library/bb762180.aspx),该函数允许您传入代表您感兴趣的用户的访问令牌
。想象一下这会有多困难。
You'll want to pinvoke the SHGetFolderLocation function (http://msdn.microsoft.com/en-us/library/bb762180.aspx) which allows you to pass in an access token that represents the user you're interested in.
No idea how difficult that will be though.
您可以选择一些选项,具体取决于您想要的方式。
选项 A:
硬编码,但适用于默认系统设置
选项 B:
查找当前用户,然后将其交换出来
现在,选项 B 尚未经过充分测试,但应该可以工作!
There are a few options that you can go with, depending on how you want to do it.
Option A:
Hard coded, but it works for default system setups
Option B:
Find for the current user, then swap it out
Now, option B hasn't been fully tested, but should work!