这是我在远程机器上安装msi文件的脚本:
Const MSIFileName = "\\<IP ADDR>\c$\MySetup\<FILENAME>"
Set WshShell = WScript.CreateObject( "WScript.Shell" )
WshShell.Run "msiexec /a " & MSIFileName & " /quiet /log c:\install.log", 1, True
当我从本地计算机运行此脚本时,该文件将安装在我运行的计算机上。相反,我希望它安装在MSIFileName
中指定的计算机上。我哪里错了?
答案 0 :(得分:0)
您正在本地主机上运行远程MSI。要在远程主机上安装远程可执行文件,可以使用WMI:
host = "<IP ADDR>"
setup = "msiexec /a ""C:\MySetup\<FILENAME>"" /quiet ..."
Set wmi = GetObject("winmgmts://" & host & "/root/cimv2")
rc = wmi.Get("Win32_Process").Create(setup, , , pid)
If rc = 0 Then
WScript.Echo "Setup started with PID " & pid & "."
Else
WScript.Echo "Starting setup failed. (" & rc & ")"
End If
以上将异步启动该过程(即Create
立即返回)。如果您需要等待远程进程完成,您必须像这样监视它:
Do
WScript.Sleep 100
Set p = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE ProcessID=" & pid)
Loop Until p.Count = 0
可能有更简单的方法可以做你想做的事,例如, PsExec
:
psexec \\<IP ADDR> msiexec /a "C:\MySetup\<FILENAME>" /quiet ...