[英]C# how can i use WMI to create user account in a remote computer
I wan to create user account in a remote machine and set some credintial to it. 我想在远程计算机上创建用户帐户并为其设置一些凭据。 i knew that we can use WMI to run batch file remotly on another machine . 我知道我们可以使用WMI在另一台计算机上远程运行批处理文件。
is there a way to run batch file using c# code to create user name and passowrd remotly on another machine 有没有一种方法可以使用c#代码运行批处理文件以在另一台计算机上远程创建用户名和密码
Instead of using a batch file, it is possible to use the classes in System.DirectoryServices. 除了使用批处理文件外,还可以使用System.DirectoryServices中的类。
// you need to supply these parameters:
string domainName = "domain";
string computerName = "computer";
string userName = "name";
string password = "password";
var machineDirectory = new DirectoryEntry(@"WinNT://" + domainName + @"/" + computerName + ",computer");
var userEntry = machineDirectory.Children.Add(userName, "user");
userEntry.Invoke("SetPassword", password);
userEntry.CommitChanges();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.