应AD部署的需要,编写了一段创建本地用户和加入用户到管理员组的脚本。脚本虽简单,但要保证正确执行还真麻烦,没有语法提醒,出现问题也莫名其妙。下面是我调试通过的代码,现公布出来供大家分享,以免调试之苦。
On Error Resume Next
Dim strUserName,strPassword
Dim objDomain,objUser
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strUserName = "clientadmin"
strPassword = "71999"
'创建用户
Set objDomain = GetObject("WinNT://" & strComputer & ",computer")
Set objUser = objDomain.Create("user",strUserName)
objUser.SetInfo
'设置密码
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
objUser.SetPassword strPassword
objUser.SetInfo
'加入管理员组
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
objGroup.Add(objUser.ADsPath)
Dim strUserName,strPassword
Dim objDomain,objUser
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
strUserName = "clientadmin"
strPassword = "71999"
'创建用户
Set objDomain = GetObject("WinNT://" & strComputer & ",computer")
Set objUser = objDomain.Create("user",strUserName)
objUser.SetInfo
'设置密码
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
objUser.SetPassword strPassword
objUser.SetInfo
'加入管理员组
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strComputer & "/" & strUserName & ",user")
objGroup.Add(objUser.ADsPath)
2006-02-24 by lig