我使用以下vbs来启用和重命名Admin本地帐户但是失败了。它不启用帐户,也不重命名。我现在为什么打结,它看起来像一个简单易用的脚本。任何线索?
sPwd = "hsc1234"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAccounts = objWMIService.ExecQuery _
("Select * From Win32_UserAccount Where LocalAccount = True and Name = 'Administrator'")
For Each objAccount in colAccounts
MsgBox objAccount.Name
objAccount.Disabled = False
objAccount.Rename("HSC1")
objAccount.SetPassword(sPwd)
Next
答案 0 :(得分:0)
好吧,最后我可以找到解决方案。此解决方案可以启用和重命名管理员帐户,也可以设置管理员密码。我在W10上的管理员默认帐户遇到了一些问题,所以我不得不在提升模式下推送脚本。
If Not WScript.Arguments.Named.Exists("elevate") ThenCreateObject("Shell.Application").ShellExecute WScript.FullName _
, """" & WScript.ScriptFullName & """ /elevate", "", "runas", 1
WScript.Quit
End If
sPwd = "hsc1234"
strComputer = "."
sUser = "XXxx"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colAccounts = objWMIService.ExecQuery("Select * From Win32_UserAccount Where LocalAccount = True and Name = 'Administrator'")
For Each objAccount in colAccounts
objAccount.Disabled = False
objAccount.Put_
objAccount.Rename sUser
'objAccount.SetPassword sPwd
Next
Set oUser = GetObject("WinNT://" & strComputer & "/" & sUser
oUser.SetPassword sPwd
oUser.Setinfo