Solved

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

Posted on 2011-03-16
6
535 Views
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"
	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

0
Comment
Question by:vhapugsea1
  • 3
  • 2
6 Comments
 

Expert Comment

by:tneubauertocg
Comment Utility
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.
0
 

Author Comment

by:vhapugsea1
Comment Utility
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?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
Comment Utility
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"
Else
	MsgBox "Installation failed. Return code: " & intReturn
End If

Open in new window


Regards,

Rob.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:tneubauertocg
Comment Utility
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.
0
 

Expert Comment

by:tneubauertocg
Comment Utility
Also - what is in the minimized "Microsoft Visual C++ Runtime Library" window when you maximize it?
0
 

Author Closing Comment

by:vhapugsea1
Comment Utility
Not really a solution...just a work-around using psexec instead of WMI to remotely execute the process.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now