Posted by: Dave | Tuesday, November 3, 2009

Script to Check Adobe Version and update if needed

Here you are Mike, I’ve played with a few scripts and had great results… but this one has to be my crowning achievement at this point.

Some background info first: We needed most of our PCs to have Adobe Reader version 8.1.4 installed. We have automatic updates for adobe blocked on the firewall, and we also couldn’t install 9.0 because it would not be supported by another piece of software. Some of the PCs still had adobe reader 7.0, most had 8.0 or 8.1. I wanted a script that got called in a login script and checked what version they had and ran a silent install of adobe 8.1.4 if needed.

First, I got myself a full exe of Adobe 8.1.3 (for some annoying reason you can only patch to 8.1.4 from 8.1.3, and there is no full install of 8.1.4). I used resources that adobe themselves provide to make a custom msi package and also set it to include the separate 8.1.4 patch. This all gets dumped into a directory on a network share that all users have access to.

I then added this line to the users login scripts (batch files) to call the script:

cscript “\\LocalServer\share\folder\adberdr81Silent\setup files\adobe814.vbs” /quiet /passive

This calls the script silently and does not ask the user if they want to run or whatever other BS safety messages Windows XP vomits at you normally when you run a file off the network.

Now the VBscript (script in blue, my comments for this post in normal):

Dim FilePath
Dim fso
Dim version
Dim WshShell

Set objFSO = CreateObject(“Scripting.FileSystemObject”)

If objFSO.FileExists(“c:\program files\adobe\reader 8.0\reader\acrord32.exe”) Then
Set objNet = WScript.CreateObject(“WScript.Network”)
strCaption = “Adobe Reader”
Set objWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2″)
For Each objSoftware in objWMI.ExecQuery(“SELECT * FROM Win32_Product Where Caption Like ‘%” & strCaption & “%’”)
version = objSoftware.Version
Next

^ This says look to see if the folder for adobe 8.0 exists on the local C:, and if it does, it searches the registry for what exact version it is and stores it in the “version” variable. If the folder for 8.0 does not exist, the script can assume that either 7.0 is installed, or no version of adobe is installed and will run the setup in the “else” option below:

Else

set objWshShell= CreateObject(“Wscript.Shell”)
set objEnviroment = objWshShell.Environment(“PROCESS”)
objEnviroment (“SEE_MASK_NOZONECHECKS”) = 1

^ This changes the registry so that it will disable those annoying open file warnings during the script

Set WshShell = WScript.CreateObject(“WScript.Shell”)
WScript.Echo WshShell.CurrentDirectory
WshShell.CurrentDirectory = “Y:\folder\adberdr81Silent\Setup Files”

^ This changes the running directory (I had trouble with some stations thinking I was trying to run setup.exe out of the windows directory, this fixed that) Y: is mapped to the “share” on the local server.

Set WshShell = WScript.CreateObject(“WScript.Shell”)
WshShell.Run “setup.exe”

set objWshShell= CreateObject(“Wscript.Shell”)
set objEnviroment = objWshShell.Environment(“PROCESS”)
objEnviroment (“SEE_MASK_NOZONECHECKS”) = 0

WScript.quit

^ This calls the setup.exe located in that folder and the custom adobe msi I made to install completely silently (among other custom settings) takes it from here. Then the script undoes the change I made to disable the open file warnings and exits the script. Adobe 8.1.4 is now installed.

End If

If version = “8.1.4″ Then

WScript.quit

^ Here we have the other option, the script finds the adobe 8.0 directory and is now going to check that version variable. For my purposes, checking if the version is 8.1.4 (highest version of reader 8 ) is what I needed. If that version is already installed the script quits and does nothing further.

Else

set objWshShell= CreateObject(“Wscript.Shell”)
set objEnviroment = objWshShell.Environment(“PROCESS”)
objEnviroment (“SEE_MASK_NOZONECHECKS”) = 1

Set WshShell = WScript.CreateObject(“WScript.Shell”)
WScript.Echo WshShell.CurrentDirectory
WshShell.CurrentDirectory = “Y:\folder\adberdr81Silent\Setup Files”

Set WshShell = WScript.CreateObject(“WScript.Shell”)
WshShell.Run “setup.exe”

set objWshShell= CreateObject(“Wscript.Shell”)
set objEnviroment = objWshShell.Environment(“PROCESS”)
objEnviroment (“SEE_MASK_NOZONECHECKS”) = 0

WScript.quit

end if

^ Otherwise, if Adobe reader 8 is found, but does not equal version 8.1.4, then the script updates it to the version required by running the silent setup. From that point the setup.exe is smart enough to just install the patch(es) needed. Adobe made these easy to customize.

So there you have it. This script was added to the login process and if the PC didn’t already have Adobe Reader 8.1.4, it would install it. Otherwise it would not do anything. Either way the end user had no idea it was happening. I’m sure this script is sloppy, but it did exactly what I needed it to do – and saved Celeste and I a shitload of tedious work – , so I was pleased.

-Dave out


Leave a response

Your response:

Categories