2013-02-19 101 views
0

我想做一個VBS的工作,它的想法是將遠程安裝一個MSI,以包含一個TXT文件的機器列表。VBScript錯誤問題:期望結束800A03F6

我越來越多的錯誤,第一個是:

錯誤的參數數目或無效的屬性賦值: 「WshShell.Exec」 27號線,CHAR 1

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

我seemd用以下方法得到:

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

然後得到:

語句行27 cahr的

有望結束29

添加&

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

現在讓我:

語句行的

有望結束27字符110

這是倒數第二個逗號

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

所以我不知道什麼是錯在這一點上,以及是否改變了整條生產線的一組是做了正確的事情。

回答

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) 
+0

工作完美感謝,下面是完整的腳本,將其用於任何用途。我仍然需要添加一些錯誤檢查,以便檢查msi是否完成。 – 2013-02-20 09:14:49

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 
+0

好吧,它看起來像你從[這裏]複製這段代碼(http://www.itsupportguides.com/vbs-scripts/vbs-script-to-install-software-remotely/)。 – serenesat 2015-05-07 11:11:48