以编程方式将本地用户添加到本地组
我正在做一个针对 WinXP、Vista 和 7 操作系统的 C# 应用程序。
其中一项功能是,我可以通过编程方式添加、删除、修改用户组集。
我可以寻求帮助如何实现这一点吗?
在 WMI 中可以做到这一点吗?我的代码主要使用 WMI 来获取用户。
目前正在使用 Windows7
我正在尝试测试此代码
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer");
localMachine.Properties["member"].Add("Chevi");
localMachine.CommitChanges();
localMachine.Close();
,但它吐出了此错误
在缓存中找不到目录属性。
我尝试枚举 Property 集合,然后得到了这个
OperatingSystem
OperatingSystemVersion
Owner
Division
ProcessorCount
Processor
Name
I am doing a C# application targeting WinXP, Vista, and 7 Operating Systems.
One feature is, I can Add, Remove, Modify the Group set to a user programmatically.
Can I ask for help how to make this happen?
Will it be possible to do this in WMI? My codes mainly using WMI to get the users..
Currently am using Windows7
I am trying to test this code
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer");
localMachine.Properties["member"].Add("Chevi");
localMachine.CommitChanges();
localMachine.Close();
and it's spitting this error
The directory property cannot be found in the cache.
I tried enumerating the Property collection and I got this
OperatingSystem
OperatingSystemVersion
Owner
Division
ProcessorCount
Processor
Name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用本地组,则可以通过调用系统
net
命令来执行此操作。例如,要将用户添加到组,您可以调用:在命令提示符处键入
net help localgroup
以获取更多信息。您还可以使用 WMI 来执行此操作。这是 VBScript,但可以适应 .NET 或您首选的编程工具包:
信用:Matt Hickman,http://www.tech-archive.net/Archive/WinXP/microsoft.public.windowsxp.wmi/2004-04/0007.html
If you're using local groups, you can do this by calling the system
net
command. For example, to add a user to a group, you'd call:Type
net help localgroup
at a command prompt for more info.You can also do this using WMI. This is VBScript but can be adapted to .NET or your preferred programming toolkit:
Credit: Matt Hickman, http://www.tech-archive.net/Archive/WinXP/microsoft.public.windowsxp.wmi/2004-04/0007.html
我还在 Visual Studio 2010 上使用 C# 开发了一款 Windows 应用程序。这是该程序的工作版本,它将把现有用户添加到特定组。
I have also developed one windows application on Visual Studio 2010, using C#. This is a working version of the program, which will add an existing user to a particular group.
等
etc etc