Go Premium for a chance to win a PS4. Enter to Win

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
?
568 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 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

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.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

916 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