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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Install a hotfix remotely? 1

Status
Not open for further replies.

tEkHEd

IS-IT--Management
Jan 29, 2003
261
GB
Hi there..

I am trying to write a script to install a hotfix on a remote machine from a list of hostnames.

I have the following code, which almost works, but installs the SW on the local machine!!

Here is my code:

Code:
	For intLoop = 1 To intMachineMax
		sOS = CMDCapture(sTools & "Reg Query " & Chr(34) & sKeyOS & Chr(34) & " \\" & strMachines(intloop))
		sValue = CMDCapture(sTools & "Reg Query " & sKeyMDAC & "/ve \\" & strMachines(intloop))
		oLog.Writeline("Host,OS,Version")		
		
		If InStr(sOS, 5.1) Then
			sOS = "Microsoft Windows XP Professional"
		ElseIf InStr(sOS, 5.0) Then
			sOS = "Microsoft Windows 2000"
		Else
			sOS = "Microsoft Windows NT"
		End If
		
		WScript.Echo sOS
		
		If InStr(sValue, 2.5) Then
			sValue = "MDAC v2.5"
		ElseIf InStr(sValue, 2.6) Then
			sValue = "MDAC v2.6"
		ElseIf InStr(sValue, 2.7) Then
			sValue = "MDAC v2.7"
		ElseIf InStr(sValue, 2.8) Then
			sValue = "MDAC v2.8"
		Elseif InStr(sValue, "registry key") Then
			'MDAC not installed, so don't pull the fix
			WScript.Quit 
		End If
		
		WshShell.Run(FixLoc & "Q832483.vbs")
		oLog.writeline(strmachines(intloop) & "," & sOS & "," & sValue)
	next

The calling script is:
Code:
'Path to HotFix
Const FixLoc = "\\MyServer\HOTFIXES\MDAC\Q832483\"
'Registry to store hot fix info
Const KeyPath = "HKLM\Software\NON Windows Installer\Hotfixes\"
'HotFix ID (key in Reg)
Const KeyVal = "Q832483"
'HotFix MSO Number
Const MSO = "MS04-003"
Const ScriptTools = "\\MyServer\ScriptTools\"
Const ForReading = 1, ForWriting = 2

Dim sCMD
Set wshShell = CreateObject("Wscript.Shell")
Set WshSysEnv = wshShell.Environment("Process")
sLocalName = UCase(WshSysEnv("COMPUTERNAME"))

sCMD = "cmd /c " & FixLoc & "ENU_Q832483_MDAC_X86.EXE /C:" & chr(34) & "dahotfix.exe /q /n" & Chr(34) & " /q"

If KeyExists (KeyPath & MSO & "\" & KeyVal) = False Then
	wshShell.run sCMD, 7, True
    wshShell.RegWrite KeyPath & MSO & "\" & KeyVal, "Installed on " & Now & " From: " & FixLoc & sCmd, "REG_SZ"
End if

' To check if a registry value exists
Public Function KeyExists(key)
	Dim key2
    On Error Resume Next
    key2 = wshShell.RegRead(key)
    If err <> 0 Then
    	KeyExists = False
    Else
    	KeyExists = True
    End If
End Function

Can anyone point me in the right direction please??
 
Shell to psexec.exe from to fire it off from a remote PC. PSexec starts a process on a remote box. I've seen some issues when it tries to use something with parameters, so usually what I do is create a temp bat file on the c:\ then have something like:
@echo off
\\server\share\update.exe -u -f -n -o -q

Then i would do:

SH.Run &quot;%comspec% /c c:\psexec.exe \\&quot; & TargetPC & &quot; -u domain\username -p password -d c:\temp.bat&quot;

Something to that effect.
 
Excellent, just what I needed.. didn't know about PSEXEC

thanks.
 
No prob. Just remember to clean up those temp batch files. I forgot during one push awhile back and I still come across machines with batches in root from it, hehe. A newer version of psexec may be out that fixes the quirk with parms that'd make the bat unnecessary. I haven't checked lately.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top