[Last Call] Learn how to a build a cloud-first strategyRegister Now


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
  • 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Integration Management Part 2
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month18 days, 9 hours left to enroll

825 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