如何使用 Windows Vista 创建用户帐户VBScript http://en.wikipedia.org/wiki/VBScript?
我正在使用以下脚本。它在 Windows XP 上工作正常,但在 Windows Vista 上出现错误:
strUserName = "username"
strPassword = "password"
strComputer = "."
set objSystem = GetObject("WinNT://" & strComputer)
set objUser = objSystem.Create("user", strUserName)
objUser.SetPassword strPassword
objUser.SetInfo
我可以在我的 Vista 机器上运行这个脚本,并且它会创建用户。
我怀疑您可能遇到了 UAC 问题。本文 https://www.winhelponline.com/blog/vbscripts-and-uac-elevation/提供一些用于提升脚本权限的选项。
选项 1 – 代码以提升的权限重新启动:
If WScript.Arguments.length = 0 Then
Set objShell = CreateObject("Shell.Application")
'Pass a bogus argument, say [ uac]
objShell.ShellExecute "wscript.exe", Chr(34) & _
WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
Else
'Add your code here
End If
选项 2 – 单独的启动器脚本:
Set objShell = CreateObject("Shell.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
strPath = FSO.GetParentFolderName (WScript.ScriptFullName)
If FSO.FileExists(strPath & "\MAIN.VBS") Then
objShell.ShellExecute "wscript.exe", _
Chr(34) & strPath & "\MAIN.VBS" & Chr(34), "", "runas", 1
Else
MsgBox "Script file MAIN.VBS not found"
End If
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)