0

我正在尝试使 vbs 工作,其想法是它将远程安装 msi,到包含 txt 文件的机器列表。

我收到多个错误,第一个是:

错误数量的参数或无效的属性分配:“WshShell.Exec”第 27 行,字符 1

WshShell.Exec "%COMSPEC% /C COPY " & StrInstallFile & " \\" & strComputer _
  & "\C$\Windows\Temp", 0, TRUE 

我似乎已经解决了这个问题:

Set WshExec = WshShell.Exec......

然后得到:

语句第 27 行的预期结尾 cahr 29

添加一个&

Set WshExec = WshShell.Exec & "%COMSPEC%.....

现在让我:

语句第 27 行的预期结尾 char 110

这是倒数第二个逗号

Set WshExec = WshShell.Exec & "%COMSPEC% /C COPY" & StrInstallFile _
  & " \\" & strComputer & "\C$\Windows\Temp", 0, TRUE

所以我不确定此时出了什么问题,以及将整行更改为一组是否正确。

4

2 回答 2

0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("MachineList.Txt", 1)
StrInstallFile="install_flash_player_11_active_x.msi"
StrNoUpdateFile="mms.cfg"
StrInstallCMD="msiexec.exe /qn /i "

Do Until objFile.AtEndOfStream

strComputer = objFile.ReadLine

' --------- Check If PC is on -------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 1 -w 1000 " & strComputer) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then

' ---------- Successful ping - run remote commands  ----------------

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


' --------- Copy msi to windows temp folder
Set oExec = WshShell.Exec("%COMSPEC% /C COPY " & StrInstallFile & " \\" & strComputer & "\C$\Windows\Temp")

' --------- execute msi file on remote machine
Set oExec = WshShell.Exec("%COMSPEC% /C psexec  \\" & StrComputer & " " & strInstallCMD & "c:\Windows\Temp\" & StrInstallFile)

' --------- Copy no "no update" file to remote machine, first line is for win7, second for xp
Set oExec = WshShell.Exec("%COMSPEC% /C COPY " & StrNoUpdateFile & " \\" & strComputer & "\C$\Windows\SysWOW64\Macromed\Flash")
Set oExec = WshShell.Exec("%COMSPEC% /C COPY " & StrNoUpdateFile & " \\" & strComputer & "\C$\Windows\system32\macromed\flash")

Else

' ---------- Unsuccessful ping - Leave computer name in MachineList.txt and continue ----------------

strNewContents = strNewContents & strComputer & vbCrLf

End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("MachineList.txt", 2)
objFile.Write strNewContents
objFile.Close
于 2013-02-20T09:21:18.710 回答
0

您正在混合 .Run 和 .Exec。.Exec 的原型:

object.Exec(strCommand)

表明您需要类似的东西:

Set oExec = WshShell.Exec("%COMSPEC% /C COPY " & StrInstallFile & " \" & strComputer & "\C$\Windows\Temp")

如果您想要 .Run ,请尝试以下操作:

Dim iRet : iRet = WshShell.Run(strCommand, [intWindowStyle], [bWaitOnReturn]) 
Dim iRet : iRet = WshShell.Run("%comspec% ...", 0, True) 
于 2013-02-19T11:06:52.803 回答