用户所属的wmi组
我有找到所有本地用户的代码:
ManagementObjectSearcher userSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_UserAccount");
foreach (ManagementObject user in userSearcher.Get())
{
if ((bool)user["LocalAccount"])
{
string UserName = (string)user["Name"];
}
}
return;
现在我想要帮助我选择用户所在的所有组的代码。我知道有一个名为 Win32_GroupUser 的表,我必须使用 PartComponent 来指示用户名,但我无法创建查询。请帮忙提供有关 WQL 的信息。
i have the code which find all local users:
ManagementObjectSearcher userSearcher = new ManagementObjectSearcher("SELECT * FROM Win32_UserAccount");
foreach (ManagementObject user in userSearcher.Get())
{
if ((bool)user["LocalAccount"])
{
string UserName = (string)user["Name"];
}
}
return;
now i want code which help me to select all groups in which user consist. I know that there is table called Win32_GroupUser and i must use PartComponent to indicate user name but i cant create query. Please help with information about WQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询将类似于:
您需要传递域名和用户名来查找关联的组。出于性能原因,我推荐 StringBuilder 类。
我从这篇文章中得出这个答案。
The query will look something like:
You need to pass the domain name and username to lookup the associated groups. For performance reasons I would recommend StringBuilder class.
I derived this answer from this article.