Solved

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

Posted on 2011-03-16
6
537 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
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")
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
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?
0
 
LVL 65

Accepted Solution

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

Open in new window


Regards,

Rob.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:tneubauertocg
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:
ID:26890820

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

Expert Comment

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

Author Closing Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

19 Experts available now in Live!

Get 1:1 Help Now