In my previous post I show 2 vbscripts to determine the versions of MS Access, as well as, Internet Explorer. But what do you do if you need to determine the version of Excel, Word, Outlook, etc? Well it can be done as well. Below is a basic, but versatile vbscript that can return the version of almost any program installed on a PC. Please note, it needs more coding to allow for exceptions, but the basic are there.
Method 1 – File System Object (FSO)
Dim oRegistry
Dim oFSO
Dim sKey
Dim sAppExe
Dim sValue
Dim sAppVersion
Const HKEY_LOCAL_MACHINE = &H80000002
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/default:StdRegProv")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sKey = "Software\Microsoft\Windows\CurrentVersion\App Paths"
'sAppExe = "excel.exe"
'sAppExe = "GROOVE.exe"
'sAppExe = "infopath.exe"
sAppExe = "MSACCESS.EXE"
'sAppExe = "MSPUB.EXE"
'sAppExe = "OneNote.exe"
'sAppExe = "OUTLOOK.EXE"
'sAppExe = "winword.exe"
'sAppExe = "firefox.exe" 'Even works with a number of other programs!
oRegistry.GetStringValue HKEY_LOCAL_MACHINE, sKey & "\" & sAppExe, "", sValue
MsgBox oFSO.GetFileVersion(sValue)
Set oFSO = Nothing
Set oRegistry = Nothing
Method 2 – WMI
Dim oRegistry
Dim oWMIService
Dim colFiles
Dim oFile
Dim sKey
Dim sAppExe
Dim sValue
Dim sAppVersion
Const HKEY_LOCAL_MACHINE = &H80000002
Set oRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}//./root/default:StdRegProv")
Set oWMIService = GetObject("winmgmts:\\.\root\cimv2")
sKey = "Software\Microsoft\Windows\CurrentVersion\App Paths"
'sAppExe = "excel.exe"
'sAppExe = "GROOVE.exe"
'sAppExe = "infopath.exe"
sAppExe = "MSACCESS.EXE"
'sAppExe = "MSPUB.EXE"
'sAppExe = "OneNote.exe"
'sAppExe = "OUTLOOK.EXE"
'sAppExe = "winword.exe"
'sAppExe = "firefox.exe" 'Even works with a number of other programs!
oRegistry.GetStringValue HKEY_LOCAL_MACHINE, sKey & "\" & sAppExe, "", sValue
Set colFiles = oWMIService.ExecQuery _
("Select * from CIM_Datafile Where Name = '" & replace(sValue, "\", "\\") & "'")
For Each oFile in colFiles
MsgBox oFile.Version
Next
Set colFiles = Nothing
Set oWMIService = Nothing
Set oRegistry = Nothing
In both cases, the procedures return a value such as: 15.0.4749.1000 which you can easily parse out the first set of numbers to identify the major version of the software (if that is what you are after).
Now, according to http://blogs.technet.com/b/heyscriptingguy/archive/2005/04/18/how-can-i-determine-the-version-number-of-a-file.aspx?Redirected=true Method 2 is best. Although both limitations of Method 1 have no impact on my usage. Furthermore, Method 1 was faster in my tests.
Also, if you are running 64-bit, then you may need to also check the
sKey = "Software\Wow6432Node\Microsoft\Windows\CurrentVersion\App Paths"
Very cool.
I was looking for a solution to my “Two different versions of Access on company computers”
and this was “IT”!
Very cool and thanks…
Whenever we remove one MS Office installation and do anther install, scanning tools detect both removed as well as existing versions. I would like to have a script which when be run on machine, will give me list of all obsolete entries of MS Office
How are you removing the installation?
Always use Option 2 from https://support.office.com/en-us/article/uninstall-office-from-a-pc-9dd49b83-264a-477a-8fcc-2fdf5dbf61d8