VIsual Basic Script (very basic!) for remote software install

Posted on 2011-03-16
Medium Priority
Last Modified: 2012-06-21
Hi all,

I have a very basic VBS (get it?) and would like some guidance specifically on lines 41 - 43.

The rest of the script works fine--it copies over my files using the C$ admin share.  Starting with line 41, I am attempting to use WMI to execute the installer process on the remote computer.

This should be fairly simple for you experts out there to show me the way.  Thank you!
Option Explicit

Dim objFSO, objShell
Dim strComputer
Dim strAllUsersDesktop
Dim strCopyTo
Dim strCopyFrom

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = WScript.CreateObject("WScript.Shell")

strComputer = InputBox("Enter computer name")
If Not CheckForComputer Then
	WScript.Echo "Computer " & strComputer & "not found"
End If

strAllUsersDesktop = "C$\Documents and Settings\All Users\Desktop\"
strCopyTo = "\\" & strComputer & "\C$\Citrix\"
strCopyFrom = "Files"

If Not objFSO.FolderExists(strCopyTo) Then
End If

objFSO.CopyFile strCopyFrom & "\*.*", strCopyTo, True
If Not objFSO.FolderExists(strCopyTo) Then
 	WScript.Echo "Problem: Failed to copy installer" 
End If

strCopyTo = "\\" & strComputer & "\" & strAllUsersDesktop
strCopyFrom = "Shortcut"
objFSO.CopyFile strCopyFrom & "\*.*", strCopyTo, True
If Not objFSO.FolderExists(strCopyTo) Then
 	WScript.Echo "Problem: Failed to copy shortcut" 
End If

MsgBox ("All files copied to: " & strComputer)

Dim GetObject
osvcRemote = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set oprocess = osvcRemote.Get("win32_process")
oprocess.create("c:\\example\example.exe /silent")
MsgBox ("Installation Successful")

Function CheckForComputer
	CheckForComputer = False
	Dim strText
	Dim objExecObject
	Dim strCommand
    strCommand = "%comspec% /c ping -n 3 -w 1000 " & strComputer & ""
    Set objExecObject = objShell.Exec(strCommand)

    Do While Not objExecObject.StdOut.AtEndOfStream
        strText = objExecObject.StdOut.ReadAll()
        If Instr(strText, "Reply") > 0 Then
			CheckForComputer = True
		End If
End Function

Open in new window

Question by:vhapugsea1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 35151954
I use two options, most frequently the objShell.run command.  In your case, delete lines 41 & 42 and have 43 be:

objShell.run ("c:\example\example.exe /silent"),1 True

You can also use objShell.exec:

'Validate the existance of the file and execute if found
If objFSO.FileExists(filename) then
     Set oExec=objshell.Exec ("c:\\example\example.exe /silent")
     Msgbox "Installation file could not be found" ' or some type of failure notification
End if

'pause the script while the installation is running

Do While oExec.status = 0
     Wscript.Sleep 100

MsgBox ("Installation Successful")

In either case I always validate the existance of the file and execute as long as it is found.

Author Comment

ID: 35152681
I have the process (a program installer) running on the remote computer, but somehow it never finishes.  In the Task Manager, I see the process sitting there doing nothing.  And in the Taskbar there is a minimized "Microsoft Visual C++ Runtime Library" window that stays there forever.  The program never gets installed.  Any ideas?
LVL 65

Accepted Solution

RobSampson earned 1000 total points
ID: 35153536
Hi, instead of this:
Dim GetObject
osvcRemote = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set oprocess = osvcRemote.Get("win32_process")
oprocess.create("c:\\example\example.exe /silent")

Open in new window

You could use PSExec instead to start the remote process.
Dim strPSExec, intReturn
strPSExec = "\\server\share\tools\psexec.exe"
strPSExec = objFSO.GetFile(strPSExec).ShortPath
intReturn = objShell.Run(strPSExec & " -accepteula -i \\" & strComputer & " c:\example\example.exe /silent", 1, True)
If intReturn = 0 Then
	MsgBox "Installation Successful"
	MsgBox "Installation failed. Return code: " & intReturn
End If

Open in new window


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 35156827
How does it behave when installing locally?  You say the process starts but never finishes.  It sounds like it is waiting for some user input (dialog box, EULA acceptance, etc).  First we need to find out if this is truely a silent install, it sounds like it isn't.

Keep an eye on one of my questions for a response on how to terminate a process that has been idle for (in my case) 2 minutes:

Please validate that /Silent switch is actually working and let me know what you find.

Expert Comment

ID: 35156850
Also - what is in the minimized "Microsoft Visual C++ Runtime Library" window when you maximize it?

Author Closing Comment

ID: 35283449
Not really a solution...just a work-around using psexec instead of WMI to remotely execute the process.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question