Install Software on multiple remote servers with the help of vbscript

Hi

I want a script which help me installing the software on the remote servers through vbscript.
I’m using following script which goes in loop after running command windows start flashing on screen.

On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\test\computers.txt", 1)

StrInstallFile="jdk-7u25-windows-i586.exe"
StrInstallCMD="msiexec.exe /qn /norestart /i C:\test\jdk-7u25-windows-i586.exe"

Do Until objFile.AtEndOfStream


strComputer = objFile.ReadLine

' --------- Check If PC is on -------------
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 1 -w 300 " & strComputer) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then

' ---------- Successful ping - run remote commands  ----------------

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")


WshShell.Exec "%COMSPEC% /C COPY " & StrInstallFile & " \\" & strComputer & "\C$\Windows\TEMP", 0, TRUE
WshShell.Exec "%COMSPEC% /C psexec \\" & strComputer & " " & StrInstallCMD &"", 0, TRUE


      Else

' ---------- Unsuccessful ping - Leave computer name in MachineList.txt and continue ----------------

strNewContents = strNewContents & strComputer & vbCrLf


      End If
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("C:\test\computers.txt", 2)
objFile.Write strNewContents

objFile.Close
ALTIMEITAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, see how this goes.

Regards,

Rob.

'On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\test\computers.txt", 1, False)

StrInstallFile="jdk-7u25-windows-i586.exe"
StrInstallCMD="msiexec.exe /qn /norestart /i C:\Windows\Temp\jdk-7u25-windows-i586.exe"

Do Until objFile.AtEndOfStream
	strComputer = Trim(objFile.ReadLine)
	If strComputer <> "" Then
		' --------- Check If PC is on -------------
		Set WshShell = CreateObject("WScript.Shell")
		If Ping(strComputer) = True Then
			' ---------- Successful ping - run remote commands  ----------------
			
			Set objWMIService = GetObject("winmgmts:" _
			    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
			
			
			WshShell.Run "%COMSPEC% /C COPY " & StrInstallFile & " \\" & strComputer & "\C$\Windows\TEMP\", 0, TRUE 
			WshShell.Run "%COMSPEC% /C psexec -accepteula \\" & strComputer & " " & StrInstallCMD &"", 0, TRUE 
	
		Else
			
			' ---------- Unsuccessful ping - Leave computer name in MachineList.txt and continue ----------------
			
			strNewContents = strNewContents & strComputer & vbCrLf
	
	
		End If
	End If
Loop

objFile.Close

Set objFile = objFSO.CreateTextFile("C:\test\computers.txt", 2)
objFile.Write strNewContents

objFile.Close 

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

Open in new window

0
ALTIMEITAuthor Commented:
Hi Rob,

Thank you for your response,
when I run the script in our environment, it throws me runtime error.
Line: 4
Char: 1
Error: File not found
Code: 800A0035
Source: Microsoft VBScript runtime error.

MAy I ask if you have any such script which help me copying the software on the remote server and then install that particular software on the server remotly.

Regards,
0
RobSampsonCommented:
This script looks like it will work. The error you get just means that it can't find C:\test\computets.txt

You need to adjust that on lines 4 and 37
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

ALTIMEITAuthor Commented:
Hi Rob,
Thank you for your reply,

I was working on the following script to install the software on the remote servers, but I'm not able to add line to ask script to copy the software on the remote server and then ask it to install that software.
can you please help me modifying the line further to copy the the software and then install it.

strUser = ""
strPassword = ""
strMSI = ""
strComputer = ""

'Get user name, cannot be blank
Do While strUser = ""
    strUser = InputBox("Enter user name", "User Name")
Loop
'Get password, cannot be blank
Do While strPassword = ""
    strPassword = InputBox("Enter password", "Password")
Loop
'Get msi package path, cannot be blank
Do While strMSI = ""
    strMSI = InputBox("Enter the path to the msi package", "MSI package")
Loop
'Get destination computer, cannot be blank
Do While strComputer = ""
    strComputer = InputBox("Enter the destination computer name", "Computer")
Loop


Const wbemImpersonationLevelDelegate = 4

Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objConnection = objwbemLocator.ConnectServer _
    (strComputer, "root\cimv2", strUser, strPassword)
objConnection.Security_.ImpersonationLevel = wbemImpersonationLevelDelegate

Set objSoftware = objConnection.Get("Win32_Product")
errReturn = objSoftware.Install(strMSI,,True)



Thank you.
0
RobSampsonCommented:
I tend not to try and use Win32_Product class, since it takes too long, and also triggers repair operations in installed software.  I'd stick with the PSExec version you originally had, and try to get that working.  Try correcting the file path as I mentioned, and see how you go.

Regards,

Rob.
0
RobSampsonCommented:
Also, you don't really need to copy the file locally for the install to work.  If you specify a UNC path to the install file, it should be accessible to each remote PC, and not require copying.

Regards,

Rob.
0
ALTIMEITAuthor Commented:
Hi Rob,

Thank you for the your response,
Actually it is an agent package, which needs to be installed through the command line by providing certain inputs.
I did try above script but it did not work.

Regards.
0
RobSampsonCommented:
OK, I suggest you try using just the PSExec line directly from a command promt, outside of the VBScript.  This way, we can test the PSExec command until it works.

In the VBScript, above this line:
			WshShell.Run "%COMSPEC% /C psexec -accepteula \\" & strComputer & " " & StrInstallCMD &"", 0, TRUE 

Open in new window


put this
			InputBox "Command", "Command", "psexec -accepteula \\" & strComputer & " " & StrInstallCMD

Open in new window


This will show you the command we are trying to run, and you can copy that directly to a command prompt to run to see what error message you get.  Play around with the command until it works.  If you need to, you may have to run the command prompt "As Administrator" first.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ALTIMEITAuthor Commented:
Hi Rob,

Thank you for your reply.
do I need to incorporate these two line in the above script or need to run it separately.

Regards.
0
ALTIMEITAuthor Commented:
Thank you for your support...
0
RobSampsonCommented:
Thanks for the grade. Sorry I didn't get back to you. The new line was meant to be put in the existing script to help you get the command right.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.