Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-02
7
Medium Priority
?
565 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 1000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/A_266-VBScri…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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