VBS Script to install software remotely

The following script has been used to remotely install Adobe Flash on a list of computers.

Requirements:

  • The pstools need to be installed on the main computer you’re running it from. The pstools can be found here http://technet.microsoft.com/en-us/sysinternals/bb896649.aspx
  • A text file called MachineList.txt. Each computer name needs to be entered into a new line.
  • The installer file, for example install_flash_player_10_active_x.msi

 

To use, change the StrInstallFile and StrInstallCMD as required.
The install file needs to placed with the VBS file and will copy to the remote computer before running.

On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("MachineList.Txt", 1)

StrInstallFile="install_flash_player_10_active_x.msi"
StrInstallCMD="msiexec.exe /qn /norestart /i C:\Windows\TEMP\install_flash_player_10_active_x.msi"

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")

WshShell.Exec "%COMSPEC% /C COPY " & StrInstallFile & " \\" & strComputer & "\C$\Windows\TEMP", 0, TRUE
WshShell.Exec "%COMSPEC% /C psexec \\" & strComputer & " " & StrInstallCMD &"", 0, TRUE

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