Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

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

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
adkdavis
Asked:
adkdavis
  • 4
  • 2
1 Solution
 
sam0x01Commented:
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
 
TasmantCommented:
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
 
TasmantCommented:
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.

 
adkdavisAuthor Commented:
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
 
TasmantCommented:
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
 
TasmantCommented:
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
 
adkdavisAuthor Commented:
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

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now