PaulDH81
asked on
Help with VBS script adding a If File exist to check version
Hello Its me again, I thought i had the solution but seems its only half complete. Problem is I need a script to check if a client has Reader 7 or 8 installed and to install the updates (or newer version). If they have version 7 then install version 7.1.0 if they have anything other then version 7 (5, 6, 8) then install version 8.1.2. With the script I have at the bottom it gets the job done ....BUT it will install on every reboot I need to add in this script a IF Exist command to check the version of the software to see if it is already up to date then go to end. Im looking for HKLM\Software\Microsoft\Wi ndows\Curr entVersion \Uninstall \{aaaaaa-a a-aaa-a-a- a-a-a-a-a- a-) something like that. Thanks.
'Start of Script
Option Explicit
Dim FSO
Dim WSH
DIM Folder
Folder = "C:\Program Files\Adobe\Acrobat 7.0\Help"
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
Set WSH = CreateObject("WScript.Shel l")
If FSO.FolderExists ("C:\Program Files\Adobe\Acrobat 7.0\Help") Then
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\Acro batReader\ ENU\Adobe Reader 7.1.0.msi"
WScript.sleep 60000
Else
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\Acro batReader8 12\AdobeRe ader8\Acro Read.msi"
WScript.sleep 60000
END IF
' End of Script
'Start of Script
Option Explicit
Dim FSO
Dim WSH
DIM Folder
Folder = "C:\Program Files\Adobe\Acrobat 7.0\Help"
Set FSO = CreateObject("Scripting.Fi
Set WSH = CreateObject("WScript.Shel
If FSO.FolderExists ("C:\Program Files\Adobe\Acrobat 7.0\Help") Then
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\Acro
WScript.sleep 60000
Else
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\Acro
WScript.sleep 60000
END IF
' End of Script
ASKER
Hi, thanks for the input ill change it to check at the registry but Ill do that later what I really need is somehow to check the registry for the version that they have and if its the current version then just go to end. So I guess the process would be check if they have v7 if yes then go check the version of v7 if not up to date then install if up to date then go to end. (if they check that v7 is not installed then check to see if its v8 is it the latest version if not then install v8. something like that. Thanks
ASKER
Trying to change the Folder its checking to the reg ..... doesn't seem to work. Can you tell me what is wrong with this script
'Start of Script
Option Explicit
Dim FSO
Dim WSH
Dim Folder
Folder = "HKEY_LOCAL_MACHINE\SOFTWA RE\Adobe\A crobat Reader\7.0"
Set FSO = CreateObject("Scripting.Fi leSystemOb ject")
Set WSH = CreateObject("WScript.Shel l")
If FSO.FolderExists(Folder) Then
msgbox "Acrobat 7"
Else
msgbox "Acrobat 8"
END IF
' End of Script
'Start of Script
Option Explicit
Dim FSO
Dim WSH
Dim Folder
Folder = "HKEY_LOCAL_MACHINE\SOFTWA
Set FSO = CreateObject("Scripting.Fi
Set WSH = CreateObject("WScript.Shel
If FSO.FolderExists(Folder) Then
msgbox "Acrobat 7"
Else
msgbox "Acrobat 8"
END IF
' End of Script
I would use the GerFileVersion method of the File System Object to figure out what version of reader they have:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
HomeDrive = objFSO.GetDriveName (WinDir)
AcroBat7Ver = objFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe")
AcroBat8Ver = objFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe") 'That might not be the right path
if AcroBat7Ver < "7.1.0" Then
wscript.echo "Old Version 7"
End If
If AcroBat8Ver < "8.1.2" Then
wscript.echo "Old Version 8"
End If
ASKER
Ah thanks jared but when I try to run the script it gets an error "Object required:"WSHSHELL"" I'm not good with scripting so please tell me whats wrong ? I kinda get the concept on what your doing but yea I dont know anything about scripting just what I search and make out trial and error. Thanks
oops... forgot that one...
add this line to the other Set commands
add this line to the other Set commands
Set WshShell = WScript.CreateObject("WScript.Shell")
ASKER
do I have to Dim the set commands ?
ASKER
So far it looks like this and it also erroring saying im missing " on line 10 char 1
Option Explicit
Dim objFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set WshShell = WScript.CreateObject("WScript.Shell")
set WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
set HomeDrive = objFSO.GetDriveName ("WinDir")
AcroBat7Ver = objFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe")
AcroBat8Ver = objFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe")
if AcroBat7Ver < "7.1.0" Then
wscript.echo "Old Version 7"
End If
If AcroBat8Ver < "8.1.2" Then
wscript.echo "Old Version 8"
End If
ASKER
OK It time for me to go home from work Ill check back in about 2 hours or so (long drive) Thanks
I don't know why it's telling you your missing a quote on line 10. That was a direct copy and paste from my scripts that use it just fine.
ASKER
Ok let me check it out at work later. Sorry my internet at home was out yesterday so couldnt respond
ASKER
Hmmm It gives me the same error missing " on line 10 char 1
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
Set HomeDrive = ObjFSO.GetDriveName ("WinDir")
AcroBat7Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe")
AcroBat8Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe")
if AcroBat7Ver < "7.1.0" Then
Wscript.echo "Old Version 7"
End If
If AcroBat8Ver < "8.1.2" Then
Wscript.echo "Old Version 8"
End If
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Take option explicit out of there and see if that makes a difference
ASKER
Hmmm same error just on line 8 char 1
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
Set HomeDrive = ObjFSO.GetDriveName ("WinDir")
AcroBat7Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe")
AcroBat8Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe")
If AcroBat7Ver < "7.1.0" Then
Wscript.echo "Old Version 7"
End If
If AcroBat8Ver < "8.1.2" Then
Wscript.echo "Old Version 8"
End If
ASKER
Just took out some things that I dont think I need in there and some how got it to work but found out just now using the AcroRd32.exe will not work since that file is not going to be 7.1.0. Its an upgrade but uses the same exe file as the old so that AcroRd32.exe will always be 7.0.8.218. Dang Thanks for the help but still kinda stuck. Do you know how to do modifty date? Ill test it out but I dont really know scripts so I dont know my commands are rite. Ill keep you posted
Sorry about the coding confusion. When I said that I copied and pasted the working code I only meant that one WshSysEnv line was copied.
You can still use GetFileVersion. There is going to be a file that has a unique file version between updates. The only question is which one, and then get the version of that file. My bet would be that there is a DLL file that changes with each version.
Check out nppdf32.dll. It looks like it might correlate with the acrobat version.
You can still use GetFileVersion. There is going to be a file that has a unique file version between updates. The only question is which one, and then get the version of that file. My bet would be that there is a DLL file that changes with each version.
Check out nppdf32.dll. It looks like it might correlate with the acrobat version.
Here is a modified version with a little more intelligence...
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
HomeDrive = ObjFSO.GetDriveName ("WinDir")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll")
End If
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe") Then
AcroBat8Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe")
End If
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0" Then
WScript.Echo AcroBat7Ver
Wscript.echo "Old Version 7"
End If
End If
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2" Then
WScript.Echo AcroBat7Ver
WScript.echo "Old Version 8"
End If
End If
ASKER
Oh thanks jared that seems to do the trick I know you have done enough but if you can can you somehow put these too scripts together yours at the top with this at the bottom. Something Like if its the lastest version then go to end if folder dont
Option Explicit
Dim FSO
Dim WSH
Folder = "C:\Program Files\Adobe\Acrobat 7.0\Help"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSH = CreateObject("WScript.Shell")
If FSO.FolderExists ("C:\Program Files\Adobe\Acrobat 7.0\Help") Then
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader\ENU\Adobe Reader 7.1.0.msi"
WScript.sleep 60000
Else
WSH.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader812\AdobeReader8\AcroRead.msi"
WScript.sleep 60000
END IF
This should fit the bill...
You will want to comment out all those echo's when you get it working how you want it.
You will want to comment out all those echo's when you get it working how you want it.
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
HomeDrive = ObjFSO.GetDriveName ("WinDir")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll")
End If
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Reader 8.0\Reader\acrord32.dll") Then
AcroBat8Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Reader 8.0\Reader\acrord32.dll")
End If
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0" Then
WScript.Echo AcroBat7Ver
Wscript.echo "Old Version 7"
WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader\ENU\Adobe Reader 7.1.0.msi"
WScript.Sleep 60000
End If
End If
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2" Then
WScript.Echo AcroBat7Ver
WScript.echo "Old Version 8"
WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader812\AdobeReader8\AcroRead.msi"
WScript.Sleep 60000
End If
End If
ASKER
Sorry was working on another task Ill test out the script now Thanks
ASKER
Hi thanks for the help and I know that It should be worth more then 500 points but the script works when I try it on a comp with v7 but when I try it on a v8 comp it does nothing. Click it and I get an hour glass for a second and then nothing. Well let me explain what im trying to do. This script is going to be a Startup script for all the comps in my company. For all the comps with v7 i need to updated to the latest v7 update as for any other version (5, 6, 8) I need to install the latest version of v8. And if they already have the up to date versions then just boot up normal dont install the files again.
ASKER
Maybe something like this, sorry if it doesnt make any sense I have no back round in scripting
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
HomeDrive = ObjFSO.GetDriveName ("WinDir")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll")
End If
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0" Then
WScript.Echo AcroBat7Ver
Wscript.echo "Old Version 7"
End If
If ObjFSO.FileExists (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe") Then
AcroBat8Ver = ObjFSO.GetFileVersion (HomeDrive & "\Program Files\Adobe\Acrobat 8.0\Reader\AcroRd32.exe")
End If
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2" Then
WScript.Echo AcroBat7Ver
WScript.echo "Old Version 8"
End If
End If
Does c:\Program Files\Adobe\Reader 8.0\Reader\acrord32.dll exist?
If the file that is being check for does not exist, then it will not do anything by design.
If the file that is being check for does not exist, then it will not do anything by design.
ASKER
yea it does C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.dll. On my test script i did it as shown but nothing it just hourglass and nothing. This is the script Im using
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists ("C:\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll")
End If
If ObjFSO.FileExists ("C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.dll") Then
AcroBat8Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.dll")
End If
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0" Then
WScript.Echo AcroBat7Ver
Wscript.echo "Old Version 7"
'WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader\ENU\Adobe Reader 7.1.0.msi"
'WScript.Sleep 60000
End If
End If
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2" Then
WScript.Echo AcroBat7Ver
WScript.echo "Old Version 8"
'WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader812\AdobeReader8\AcroRead.msi"
'WScript.Sleep 60000
End If
End If
start putting in some echo's to see where the script is tripping up. If the AcroBat7/8Ver is not showing up with some numbers, then there is something going on in those lines of code.
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists ("C:\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Acrobat 7.0\Reader\Browser\nppdf32.dll")
End If
If ObjFSO.FileExists ("C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.dll") Then
AcroBat8Ver = ObjFSO.GetFileVersion ("C:\Program Files\Adobe\Reader 8.0\Reader\AcroRd32.dll")
End If
WScript.Echo "AcroBat 7 Version: " & AcroBat7Ver
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0" Then
Wscript.echo "Old Version 7"
'WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader\ENU\Adobe Reader 7.1.0.msi"
'WScript.Sleep 60000
End If
End If
WScript.Echo "AcroBat 8 Version: " & AcroBat8Ver
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2" Then
WScript.echo "Old Version 8"
'WSHShell.Run "msiexec /qr /i " & chr(34) & "\\server\Application\AcrobatReader812\AdobeReader8\AcroRead.msi"
'WScript.Sleep 60000
End If
End If
ASKER
Ok Ill start testing now ill give you result in a bit
ASKER
LOL OMG i found out what happend....... the file that i used for version 8 (AcroRd32.dll) it was already version 8.1.2 so thats why it did nothing. Mans ...... so careless on my part. And I also changed it on version 7 also to check the same file. It has the right version so easier. Here is my script at the bottom.
Option Explicit
Dim ObjFSO
Dim WshSysEnv
Dim WshShell
Dim WinDir
Dim HomeDrive
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshSysEnv = WshShell.Environment("SYSTEM")
Dim AcroBat7Ver
Dim AcroBat8Ver
If ObjFSO.FileExists ("C:\Program Files\Adobe\Acrobat
7.0\Reader\AcroRd32.dll") Then
AcroBat7Ver = ObjFSO.GetFileVersion ("C:\Program
Files\Adobe\Acrobat 7.0\Reader\AcroRd32.dll")
End If
If ObjFSO.FileExists ("C:\Program Files\Adobe\Reader
8.0\Reader\AcroRd32.dll") Then
AcroBat8Ver = ObjFSO.GetFileVersion ("C:\Program
Files\Adobe\Reader 8.0\Reader\AcroRd32.dll")
End If
If AcroBat7Ver <> "" Then
if AcroBat7Ver < "7.1.0.649" Then
'WScript.Echo AcroBat7Ver
'Wscript.echo "Old Version 7"
WSHShell.Run "msiexec /qr /i " & chr(34) &
"\\server\Application\AcrobatReader\ENU\Adobe Reader 7.1.0.msi"
WScript.Sleep 60000
End If
End If
If AcroBat8Ver <> "" Then
If AcroBat8Ver < "8.1.2.86" Then
WScript.Echo AcroBat8Ver
WScript.echo "Old Version 8"
'WSHShell.Run "msiexec /qr /i " & chr(34) &
"\\server\Application\AcrobatReader812\AdobeReader8\AcroRead.msi"
'WScript.Sleep 60000
End If
End If
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks guys Ill split the points accordingly, but let me just get this deployed first. Sorry its hard to get help like this. If I start another question I might not get any help for a while. But thanks
ASKER
I would give them an A+ is they had that option. Very good I just love EE, jared_luker was great he went above and beyond the call of duty I wish i could give him more points lol thanks guys
Thanks for the props and the points..
I think what you need to do is check this..
HKEY_LOCAL_MACHINE\SOFTWAR