snooz Posted January 2, 2007 Posted January 2, 2007 (edited) I found a really easy way to incorporate vb code into my batch scripts. First let me give you some history of what I was trying to accomplish.My company has about 4 different versions of Adobe Reader in the environment. So we are looking to upgrade everyone to version 8. We also have about 300 people who already have version 8 and we only need to automate proxy credentials for the autoupdater.The best way to determine versions is to check the EXE. Registry keys can sometimes be unreliable so it is better to be safe than sorry.I ran into another problem where machines that had version 7.08 were missing the cached MSI and MST so when version 8 tried to upgrade it failed with a 1706 "Can't find source" when trying to uninstall it.Here is what you can do to check file versions, set conditions and perform tasks off of that. I will break my script up into parts to explain the logic.@echo offECHO SET objFSO = CreateObject("Scripting.FileSystemObject") >8.vbsECHO Wscript.stdout.write objFSO.GetFileVersion("%ProgramFiles%\Adobe\Reader 8.0\Reader\AcroRd32.exe") >>8.vbsFOR /F %%a IN ('CSCRIPT /NOLOGO 8.vbs') DO IF "%%a" GEQ "8.0.0.456" GOTO UPDATEECHO SET objFSO = CreateObject("Scripting.FileSystemObject") >708.vbsECHO Wscript.stdout.write objFSO.GetFileVersion("%ProgramFiles%\Adobe\Reader\AcroRd32.exe") >>708.vbsFOR /F %%a IN ('CSCRIPT /NOLOGO 708.vbs') DO IF "%%a" EQU "7.0.8.218" GOTO 708GOTO INSTALLWe can use FileSystemObject to check file versions, then pipe the logic into a vbs file, execute the vbs and then if it does or does not meet your criteria it performs the specified task. You will notice GEQ and EQU in my DO IF logic and this is what they stand for:EQU : equalNEQ : not equalLSS : less than <LEQ : less than or equal <=GTR : greater than >GEQ : greater than or equal >=So in my first check if the version is greater than or equal to 8.0.0.456 it jumps to the update section of my script.Next version check is for Reader 7.08 because our images are missing the cached MST and MSI. If AcroRd32.exe is equal to 7.0.8.218 it goes to the 708 sectionInstead of using GOTO you can simply put a command-line like msiexec etc:708copy /y .\Reader708\reader708.* %TEMP%reg add "HKCR\Installer\Products\68AB67CA7DA73301B7447A8000000020" /v Transforms /t REG_SZ /d "%TEMP%\Reader708.mst" /freg add "HKCR\Installer\Products\68AB67CA7DA73301B7447A8000000020\SourceList" /v PackageName /t REG_SZ /d "Reader708.msi" /freg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\68AB67CA7DA73301B7447A8000000020\InstallProperties" /v LocalPackage /t REG_SZ /d "%TEMP%\Reader708.msi" /fGOTO INSTALLTo get around the source problem I copy the MSI and MST to the %TEMP% folder and then change the appropriate installer keys to point to the %TEMP% folder instead of what it was before. :INSTALLmsiexec /i Reader8.msi /norestart /qb!-del /q %TEMP%\Reader708.*GOTO UPDATEThis is self explanatory.:UPDATEmd "%USERPROFILE%\Local Settings\Application Data\Adobe\Updater5"md "%USERPROFILE%\Local Settings\Application Data\Adobe\ESD"copy /y AdobeUpdaterPrefs.dat "%USERPROFILE%\Local Settings\Application Data\Adobe\Updater5"copy /y Prefs.dat "%USERPROFILE%\Local Settings\Application Data\Adobe\ESD"Since Reader 8 is already installed at this point I simply need to automate proxy credentials for the AutoUpdater. The credentials are found in the following files:"%USERPROFILE%\Local Settings\Application Data\Adobe\Updater5\AdobeUpdaterPrefs.dat""%USERPROFILE%\Local Settings\Application Data\Adobe\ESD\Prefs.dat"In closing this method goes beyond file checking, you could use this to basically do any kind of querying with vbscript. VBScript is much easier when you are querying for information. So pretty much the sky is the limit. I figured giving and example would be easier to explain rather than just giving you the commands.If you have any questions let me know, I am pretty busy but I will check the site when I can. Edited January 2, 2007 by snooz
snooz Posted January 2, 2007 Author Posted January 2, 2007 Nothing new there! There are no posts on it.
gunsmokingman Posted January 3, 2007 Posted January 3, 2007 Here is your cmd as a full VBS script. I use the VBS script to start the cmd promt to install Adobe.This will not show the Cmd Promt Window, as I have it set to be hidden from the VBS Script.I only have tested to make sure there is no run time errors, I do not use Adobe, so check theinstall function to make sure it is correct.Save As InstallAdobe.vbsDim Fso : Set Fso = CreateObject("Scripting.FileSystemObject") Dim Act : Set Act = CreateObject("Wscript.Shell") Dim Adobe : Adobe = Act.ExpandEnvironmentStrings("%ProgramFiles%\Adobe\Reader 8.0\Reader\AcroRd32.exe")'/-> CHECK FOR FILE EXIST THEN CHECK THE VERSION If Fso.FileExists(Adobe) Then If InStr(Fso.GetFileVersion(Adobe),"8.0.0.456") Then Act.Popup "You Have The Latest Version Of Adobe",5,"Latest Version",4128 Else Act.Popup "Detected The Old Version Of Adobe"&_ vbCrLf & "Preparing To Install The Newest Version",5,"Install Adode", 4128 Install() End If Else MsgBox "There Is No Adobe Directory",4128,"Missing Adobe" End If '/-> THIS CAN ONLY RUN IF IT NOT THE CURRENT VERSION OF ADOBE Function Install() Act.Run("%comspec% /C @Echo Off && CLS && Mode 62,9 && Color 3F &&" &_ "copy /y .\Reader708\reader708.* %TEMP% && "&_ "reg add "&_ """HKCR\Installer\Products\68AB67CA7DA73301B7447A8000000020"""&_ "/v Transforms /t REG_SZ /d ""%TEMP%\Reader708.mst"" /f"&_ "&& reg add "&_ """HKCR\Installer\Products\68AB67CA7DA73301B7447A8000000020\SourceList"""&_ " /v PackageName /t REG_SZ /d ""Reader708.msi"" /f &&"&_ "reg add "&_ """HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\"""&_ "Products\68AB67CA7DA73301B7447A8000000020\InstallProperties"&_ " /v LocalPackage /t REG_SZ /d ""%TEMP%\Reader708.msi"" /f &&"&_ "Start /Wait msiexec /i Reader8.msi /norestart /qb!- &&"&_ "del /q %TEMP%\Reader708.*"&_ "md "&_ """%USERPROFILE%\Local Settings\Application Data\Adobe\Updater5""" &_ "md "&_ """%USERPROFILE%\Local Settings\Application Data\Adobe\ESD"""&_ "copy /y AdobeUpdaterPrefs.dat "&_ """%USERPROFILE%\Local Settings\Application Data\Adobe\Updater5"""&_ "copy /y Prefs.dat "&_ """%USERPROFILE%\Local Settings\Application Data\Adobe\ESD"""),0,True End Function '/-> DELETE THE VBS FILE UNCOMMENT TO MAKE ACTIVE' Fso.DeleteFile(WScript.ScriptFullName)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now