Solved

VB Script to query remote computer and upgrade software on that remote computer based on registry value

Posted on 2011-03-02
7
557 Views
Last Modified: 2012-05-11
I'm new to Visual Basic scripting and I need urgent help to create a script that I can run to update Adobe Reader software on Remote Computers. The script will read a text file to obtain remote computer names, connect to the remote computers and query the registry for a string value then upgrade Adobe Reader to most current version based on the string value returned from registry query. I've searched the internet for assistance, but I keep going around and around and still no product. I running the vb script from one of our servers. Here's what I have so far...

************************************
Rem This vb script will open and read a txt file that consist of workstation names that need Adobe updates

Rem Initializing Variables
Const ForReading = 1
Const REGQ = "REG QUERY "

Rem Creating the objects:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

Rem Open NIPR_Workstations text file for reading:
Set objTextFile = objFSO.OpenTextFile("c:\Adobe products\NIPR_Workstations.txt", ForReading)
 
Rem Read text file all at once and store information in a variable
strText = ObjTextFile.ReadAll
objTextFile.Close
arrComputers = Split (strText,VbCrLf)

For Each strArg in arrComputers
        strRegKey="HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & "DisplayVersion" & "\9.4.1"  
     Set objExec = objShell.Exec("cmd /c " & REGQ & strRegKey & " \\" & strArg)
   
Do While Not objExec.StdOut.AtEndOfStream
strOutput=objExec.StdOut.ReadLine()
If InStr(strOutput) <> "9.4.1"  
 Then
rem This is where I want it to call msiexec to upgrade Adobe Reader
Wscript.Echo strOutput
End If
Loop

NOTE: This is what I want to call to update Adobe:
msiexec /p /qn adberdrupd942_all_incr.msp /norestart
0
Comment
Question by:adkdavis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
sam0x01 earned 500 total points
ID: 35017135
You could try psexec
Set objExec=nothing
Set objExec = objShell.Exec("psexec \\" & strArg & " msiexec /p /qn \\server\share\path\adberdrupd942_all_incr.msp /norestart")

Open in new window

0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35017149
Try the following code
'This vb script will open and read a txt file that consist of workstation names that need Adobe updates

'Initializing Variables
Const ForReading = 1
Const REGQ = "REG QUERY "

'Creating the objects:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

'Open NIPR_Workstations text file for reading:
Set objTextFile = objFSO.OpenTextFile("c:\Adobe products\NIPR_Workstations.txt", ForReading)
 
Do Until objTextFile.AtEndOfStream
	strComputer = objTextFile.ReadLine
	
	'Bind to Remote Registry
	Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
	strComputer & "\root\default:StdRegProv")

	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	strValueName = "DisplayName"
	strValueVersion = "DisplayVersion"
	
	'Enum subKeys (list of all products installed)
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	 
	For Each subkey In arrSubKeys
		On Error Resume Next
		
		'Get Name and Version values for each product 
    	oReg.GetString HKEY_LOCAL_MACHINE,strKeyPath & "\" subkey & ,strValueName,strValueN
    	oReg.GetString HKEY_LOCAL_MACHINE,strKeyPath & "\" subkey & ,strValueName,strValueV
    	
    	'Do we find Acrobat in the name? Set what you want
    	If InStr(1,LCase(strValueN),Lcase("acrobat")) > 0 Then
    		'Do we find 9.4.1 in the version?
    		If strValueV = "9.4.1" Then
	    		Set objWMIService = GetObject("winmgmts:" & _
				"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
				Set objProcess = objWMIService.Get("Win32_Process")
				
				'The command to run, provide UNC path to access MSP
				strCommand = "msiexec /p /qn \\server\share\adberdrupd942_all_incr.msp /norestart"
				intReturn = objProcess.Create(strCommand, Null, Null, intProcessID)
			End If
		End If
		
	Next
	oReg = Null
	strValueName = Null
	strValueVersion = Null
	intReturn = Null
Loop
objTextFile.Close

Open in new window

0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35017172
mistake in some part

'This vb script will open and read a txt file that consist of workstation names that need Adobe updates

'Initializing Variables
Const ForReading = 1
Const REGQ = "REG QUERY "

'Creating the objects:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

'Open NIPR_Workstations text file for reading:
Set objTextFile = objFSO.OpenTextFile("c:\Adobe products\NIPR_Workstations.txt", ForReading)
 
Do Until objTextFile.AtEndOfStream
	strComputer = objTextFile.ReadLine
	
	'Bind to Remote Registry
	Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
	strComputer & "\root\default:StdRegProv")

	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	strValueName = "DisplayName"
	strValueVersion = "DisplayVersion"
	
	'Enum subKeys (list of all products installed)
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	 
	For Each subkey In arrSubKeys
		On Error Resume Next
		
		'Get Name and Version values for each product 
    	oReg.GetString HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,strValueName,strValueN
    	oReg.GetString HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,strValueName,strValueV
    	
    	'Do we find Acrobat in the name? Set what you want
    	If InStr(1,LCase(strValueN),Lcase("acrobat")) > 0 Then
    		'Do we find 9.4.1 in the version?
    		If strValueV = "9.4.1" Then
	    		Set objWMIService = GetObject("winmgmts:" & _
				"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
				Set objProcess = objWMIService.Get("Win32_Process")
				
				'The command to run, provide UNC path to access MSP
				strCommand = "msiexec /p /qn \\server\share\adberdrupd942_all_incr.msp /norestart"
				intReturn = objProcess.Create(strCommand, Null, Null, intProcessID)
			End If
		End If
		
	Next
	oReg = Null
	strValueName = Null
	strValueVersion = Null
	intReturn = Null
Loop
objTextFile.Close

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:adkdavis
ID: 35033904
Tasmant,
        Thank you for your solution.  I am still having a problem because it is not enumerating the product code subkeys in the registry (I hope I stated this correctly). For instance, information about Adobe Reader shows up {AC76BA86-7AD7-1033-7B44-A94000000001} subkey from HKLM/Software/Microsoft/Windows/CurrentVersion/Uninstall. I added echo statements to see what was being passed and it jumped smack in the middle of the registry. Then I see no values being passed to strValueN nor strValueV...it appears to have null values. I tried declaring both as DIM strValueN and Dim StrValueV. With all of that...it is not executing the commands. Please help if you have other suggestions.

Thanks!
0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35034530
Sorry i didn't really tested it, i've done some corrections, added verbose if you need to troubleshoot.
This time i've tested it a bit more, but not the launch process.



'This vb script will open and read a txt file that consist of workstation names that need Adobe updates

'Initializing Variables
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1

'Creating the objects:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")

'Open NIPR_Workstations text file for reading:
Set objTextFile = objFSO.OpenTextFile("c:\Adobe products\NIPR_Workstations.txt", ForReading)

Do Until objTextFile.AtEndOfStream
	strComputer = objTextFile.ReadLine
	
	'Bind to Remote Registry
	Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ 
	strComputer & "\root\default:StdRegProv")

	strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
	strValueName = "DisplayName"
	strValueVersion = "DisplayVersion"
	
	'Enum subKeys (list of all products installed)
	oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
	 
	For Each subkey In arrSubKeys
		'WScript.Echo subkey
		
		'Get Name and Version values for each product
    	oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,strValueName,strValueN
    	oReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath & "\" & subkey,strValueVersion,strValueV
    	'WScript.Echo strValueN
    	'WScript.Echo strValueV
    	
    	'Do we find Acrobat in the name? Set what you want
    	If InStr(1,LCase(strValueN),Lcase("acrobat")) > 0 Then
    		
    		'Do we find 9.4.1 in the version?
    		If strValueV = "9.4.1" Then
    			'WScript.Echo "Found!"
	    		Set objWMIService = GetObject("winmgmts:" & _
				"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
				Set objProcess = objWMIService.Get("Win32_Process")
				
				'The command to run, provide UNC path to access MSP
				strCommand = "msiexec /p /qn \\server\share\adberdrupd942_all_incr.msp /norestart"
				intReturn = objProcess.Create(strCommand, Null, Null, intProcessID)
				
				'WScript.Echo "Result launching process:" & intReturn
				'Refer to the following URL to know the signification of the return code
				'http://msdn.microsoft.com/en-us/library/aa389388%28VS.85%29.aspx
			End If
		End If
		
		'Empty Registry Value
		strValueN = Null
		strValueV = Null
		
	Next
	
	'Empty Variables
	oReg = Null
	strValueName = Null
	strValueVersion = Null
	intReturn = Null
Loop
objTextFile.Close

Open in new window

0
 
LVL 11

Expert Comment

by:Tasmant
ID: 35034552
In fact if we don't really know the GUID of the application (or maybe could it change over the time), we loop through each subkey ({AC76BA86-7AD7-1033-7B44-A94000000001} ....) to find "Acrobat" in displayname and the displayversion you look for. This should be found only one time, and in this case we launch the command.
0
 

Author Closing Comment

by:adkdavis
ID: 37260606
The believe the coding was partially complete or it  just wouldn't work in our environment. I tried several times. We resolved out issue another way.

Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

624 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