Link to home
Start Free TrialLog in
Avatar of vhapugsea1
vhapugsea1Flag for United States of America

asked on

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

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"
	WScript.Quit
End If

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

If Not objFSO.FolderExists(strCopyTo) Then
	objFSO.CreateFolder(strCopyTo)
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
	Loop
End Function

Open in new window

Avatar of tneubauertocg
tneubauertocg
Flag of United States of America image

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

MsgBox ("Installation Successful")


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

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:
ID:26890820

Please validate that /Silent switch is actually working and let me know what you find.
Also - what is in the minimized "Microsoft Visual C++ Runtime Library" window when you maximize it?
Not really a solution...just a work-around using psexec instead of WMI to remotely execute the process.