更新时间:2023-12-03 23:23:40
以下code是很好的工作在我的Windows 7的:
The following code is well working on my Windows Seven :
DirectoryEntry deComputer = new DirectoryEntry("WinNT://MyComputer,computer");
DirectoryEntry deUser = deComputer.Children.Add("JPB", "user");
deUser.Invoke("SetPassword", new object[] { "Password" });
deUser.Properties["Description"].Add("user $userName");
deUser.Properties["userflags"].Add(512);
deUser.Properties["passwordExpired"].Add(1);
deUser.Properties["LoginScript"].Add("start.cmd");
deUser.CommitChanges();
该脚本文件Start.cmd是present在目录:
The script file Start.cmd is present in the directory :
%systemroot%\system32\repl\import\Scripts
下面是PowerShell中的同样的事情:
Here is the same thing in PowerShell :
$computer = "MyComputer"
$userName = "jpb"
$objComputer = [ADSI]"WinNT://$computer"
$objUser = $objComputer.Create('user', $userName)
$objUser.SetPassword("Password")
$objUser.PSBase.InvokeSet('Description', "user $userName")
$objUser.PSBase.InvokeSet('LoginScript', "start.cmd")
$objUser.PSBase.InvokeSet('userflags', 512)
$objUser.PSBase.InvokeSet('passwordExpired', 1)
$objUser.SetInfo();
我希望它能帮助
I hope it helps
JP