0

下面的脚本可以按预期在 Windows XP 上运行。脚本 abc.bat 将以管理员身份运行,无需提示输入密码(密码自动提供)。但是相同的脚本在我们的 Windows 7 Box 上不起作用。是否需要进行任何更改?我没有使用 VB 脚本的经验。谢谢!

Option Explicit

Const USER               = "administrator"
Const PASS               = "*********"
Const WSNAME_COMMANDLINE = "C:\support\abc.bat"

Dim fso         : Set fso = CreateObject("Scripting.FileSystemObject")
Dim WSHShell    : Set WshShell = CreateObject("WScript.Shell")
Dim WshNetwork  : Set WshNetwork = CreateObject("WScript.Network")
Dim oDic        : Set oDic = CreateObject("Scripting.Dictionary")
Dim objArgs     : Set objArgs = WScript.Arguments
Dim oProcessEnv : Set oProcessEnv = WshShell.Environment("PROCESS")

Dim sPathToRunAs, iReturnCode

sPathToRunAs = oProcessEnv("SystemRoot")&"\System32\runas.exe"
''msgbox sPathtorunas

if Not fso.FileExists(sPathToRunAs) Then : WScript.Quit(1) 'Can't find RunAs

'''msgbox "runas /user:" & USER & " " & CHR(34) & WSNAME_COMMANDLINE & CHR(34)
iReturnCode=WshShell.Run("runas /user:" & USER & " " & CHR(34) & WSNAME_COMMANDLINE & CHR(34), 2, FALSE)

Wscript.Sleep 40                  ' Time for window to open.
WshShell.AppActivate(sPathToRunAs)' Activate the Window
Wscript.Sleep 3
WSHShell.SendKeys PASS & "~"      ' Send the password
Wscript.Sleep 3

''msgbox "done"
4

1 回答 1

0

您是否在禁用 UAC(用户帐户控制)的 Windows 7 上尝试了该脚本?

您可以在此处找到有关禁用 UAC 的操作方法:http: //windows.microsoft.com/en-US/windows-vista/Turn-User-Account-Control-on-or-off

如果 UAC 是您的问题的原因,您可以使用 windows 任务调度程序来避免这种情况,就像这里解释的那样:http: //poundcomment.wordpress.com/2011/03/18/how-to-create-a-whitelist- uac-for-windows-7/

于 2012-10-10T14:30:39.720 回答