VBS or Bat - Determine OS and Office Version
Solution 1
Although the the Office part is kind of slow, it does work.
Just include this inside a file with a name like getversions.vbs
On my computer, it printed:
Microsoft Windows 8 Enterprise
Microsoft Office 32-bit Components 2013, Version15
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption
Next
Set colSoft = objWMIService.ExecQuery("SELECT * FROM Win32_Product WHERE Name Like 'Microsoft Office%'")
If colSoft.Count = 0 Then
wscript.echo "NO OFFFICE INSTALLED"
else
For Each objItem In colSoft
Wscript.echo objitem.caption & ", Version" & Left(objItem.Version, InStr(1,objItem.Version,".")-1)
exit for
Next
End If
Solution 2
Save this (VB Script) file as GetVersions.vbs. It works Regards, Shaun
Option Explicit ' Enforce variable declaration
' Declare objects
Dim oShell
Dim sOSVersion
Dim lOfficeVersion
Set oShell = CreateObject("WScript.Shell")
On Error Resume Next
sOSVersion = oShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")' Read the registry for the operating system version
lOfficeVersion = GetOfficeVersionNumber() ' Read the office version from the function
MsgBox "sOSVersion = " & sOSVersion & vbCrLf & "lOfficeVersion = " & lOfficeVersion
Function GetOfficeVersionNumber()
GetOfficeVersionNumber = "" ' or you could use "Office not installed"
Dim sTempValue
' Read the Classes Root registry hive (it is a memory-only instance amalgamation of HKCU\Software\Classes and HKLM\Software\Classes registry keys) as it contains a source of information for the currently active Microsoft Office Excel application major version - it's quicker and easier to read the registry than the file version information after a location lookup). The trailing backslash on the line denotes that the @ or default registry key value is being queried.
sTempValue = oShell.RegRead("HKCR\Excel.Application\CurVer\")
If Len(sTempValue) > 2 Then GetOfficeVersionNumber = Replace(Right(sTempValue, 2), ".", "") ' Check the length of the value found and if greater than 2 digits then read the last two digits for the major Office version value
End Function ' GetOfficeVersionNumber
brink668
Updated on June 18, 2022Comments
-
brink668 almost 2 years
Does anyone have a script that can determine the Windows OS and Office Version in the same script.
I have bits and pieces of the script but I can't seem to figure out how to incorporate both OS and Office Version in the script. I started out in bat now I moved on to VBS as it seems to be able to provide more details however, if someone could just help out with logic in below I might be able to move forward.
I would like to know how I can setup a script like this.
If Windows 7 64bit & Office 2010 do this If Windows XP 32bit & Office 2007 do this If Windows 7 & Office 2007 do this
CODE FOR Detecting Windows Version -- BAT SCRIPT
Echo Please wait.... detecting Windows OS version... ver | find "2003" > nul if %ERRORLEVEL% == 0 goto done ver | find "XP" > nul if %ERRORLEVEL% == 0 goto ver_xp ver | find "2000" > nul if %ERRORLEVEL% == 0 goto done ver | find "NT" > nul if %ERRORLEVEL% == 0 goto done if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit systeminfo | find "OS Name" > %TEMP%\osname.txt FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i echo %vers% | find "Windows 7" > nul if %ERRORLEVEL% == 0 goto ver_7 echo %vers% | find "Windows Server 2008" > nul if %ERRORLEVEL% == 0 goto done echo %vers% | find "Windows Vista" > nul if %ERRORLEVEL% == 0 goto ver_7 goto warnthenexit