C#如何使用WMI在远程计算机中创建用户帐户

C#如何使用WMI在远程计算机中创建用户帐户,c#,asp.net,C#,Asp.net,我希望在远程计算机中创建用户帐户,并为其设置一些凭据。 我知道我们可以使用WMI在另一台机器上远程运行批处理文件 是否有一种方法可以运行批处理文件,使用c#代码在另一台计算机上远程创建用户名和密码而不是使用批处理文件,可以使用System.DirectoryServices中的类 // you need to supply these parameters: string domainName = "domain"; string computerName = "computer"; strin

我希望在远程计算机中创建用户帐户,并为其设置一些凭据。 我知道我们可以使用WMI在另一台机器上远程运行批处理文件


是否有一种方法可以运行批处理文件,使用c#代码在另一台计算机上远程创建用户名和密码

而不是使用批处理文件,可以使用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();