Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remote Install Problem

Status
Not open for further replies.

wotsit

MIS
Oct 18, 2002
47
0
0
GB
Hi, I'm hoping somebody could help me please?

I need to install some software on all of our servers in a domain (200+), remotely using a script.

I put together the vb script below, which successfully installs an msi file on the local computer. For testing purposes, I am using the winzip install file as it's a quick install:

################
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
wscript.echo "------"
wscript.echo "Installing Winzip please wait..."
ErrReturn = objSoftware.Install("\\TestServer\software\winzip120.msi", , ALL_USERS)
###############

What I need to do now, is for the script to read the server names from an input file, run a ping command and check connectivity, then either install the msi file or record the server is not available in an output file.

I put together the script below. It works in the sense that it successfully reads through the list of servers, tests connectivity to them and then records the results in the output file. However, it doesn't install the msi file on the remote servers.

###############

Option Explicit
'On Error Resume Next

' Variables

Dim objLocalWMIService, objWMIService, WSHShell, objService, objSoftware, ALL_USERS, ErrReturn
Dim objFSO, oFSO, objInFile, objOutFile, strFile, strOutData, strOutFile, strNoData, strComputer, OTextStream, RemotePC, strIPAddress, strComputerName
Dim objPing, objStatus
Dim IsReachable

' Input/Output Files

Set objFSO = CreateObject("Scripting.FileSystemObject")
strOutFile = "C:\software\results.csv"
Set objOutFile = objFSO.CreateTextFile(strOutFile, True)

'open the file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
set WSHShell = wscript.createObject("wscript.shell")

' Open Input file

Set oTextStream = oFSO.OpenTextFile("C:\Software\servers.txt")
'make an array from the input file
RemotePC = Split(oTextStream.ReadAll, vbNewLine)
'close the data file
oTextStream.Close

For Each strComputer In RemotePC

' Ping IP address

Set objLocalWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objPing = objLocalWMIService.ExecQuery("Select * From Win32_PingStatus Where Address = '" & strComputer & "' and StatusCode=0")
IsReachable = objPing.Count > 0
If IsReachable Then


' Check for wmi connection

set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number <> 0 Then
'Wscript.StdOut.Write "wmi error: " & err.number
strOutData = strComputer & ";"" Unable to connect to server, WMI error:" & err.number & "" & vbCrLf & vbCrLf
objOutFile.Write strOutData
err.clear
else

' Install software

Set objService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objSoftware = objwmiService.Get("Win32_Product")
wscript.echo "______________________________________"
wscript.echo "Installing Winzip"
wscript.echo "______________________________________"
errReturn = objSoftware.Install("\\TestServer\software\winzip120.msi", , ALL_USERS)


' Write data to .csv file

strOutData = strComputer & ";" & StrComputerName & ";" & vbCrLf & vbCrLf
objOutFile.Write strOutData

end if


' If server cannot be pinged then write server offline details to .csv file

Else
strNoData = strComputer & "; Computer Not Online or Cannot Ping." & vbCrLf
objOutFile.Write strNoData

End If

wscript.echo "Install Complete"

next
################

Can anybody shed any light on where I am going wrong please?

Thank you,
H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top