Solved

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

Posted on 2011-03-02
7
529 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
  • 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

18 Experts available now in Live!

Get 1:1 Help Now