Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get name of the installed MS Office Software (not the version) 1

Status
Not open for further replies.

Mickey Rourke

IS-IT--Management
Oct 17, 2019
1
DE
Hi all,

actually I am using the following function down below within my vbs to get information about the actual installed MS Office software. But the full name of the installed office software eg. "Microsoft Office Professional Plus 2016" is not a result of my query I set it on my own depeding on what registry key is found and that's bullshit. The registry key only says that it is Version 16.0 or 15.0 and does not deliver the Office Edition (Professional or Professional Plus). Does anyone know how to get the complete name including the edition (from local computer)?

This is my function

Function GetOfficeVer()

sRegPre = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\"
sRegPost1 = "\Common\FilesPaths\"
sRegPost2 = "\Common\InstallRoot\"
Select Case True
Case RegKeyExists(sRegPre & "16.0" & sRegPost1)
sOfficeVer = "MS Office Professional Plus 2016"
Case RegKeyExists(sRegPre & "15.0" & sRegPost2)
sOfficeVer = "MS Office Professional Plus 2013"
Case Else
sOfficeVer = "Office not installed"
End Select
GetOfficeVer = sOfficeVer
End Function
 
Refer to this link ==> VBS or Bat - Determine OS and Office Version

Code:
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
 
a) Sadly this will not provide what the OP asks for: the full name of the installed office software eg. "Microsoft Office Professional Plus 2016"
b) "SELECT * FROM Win32_Product" is not advised if it can be avoided as it has some (sometimes serious) side effects, and also is slow to the way it works (see the warning section in the Microsoft documentation

*Edited for clarity*
An alternative WMI technique involving a simple registry read of HKLM\Software via VBS is also prone to apparently incorrect results, since by default even on a 64bit platform VBS runs as 32bit, and thus only has access to 32bit nodes in registry - and the uninstall keys we want for Office are in the 64bit node

We can get around this, by using a slightly non-standard method of invoking WMI, e.g.

Code:
[blue]    strComputer = "."
    Const HKLM = &H80000002
    Set objCtx = CreateObject("WbemScripting.SWbemNamedValueSet")
    objCtx.Add "__ProviderArchitecture", 64 [COLOR=green]' 32bit or 64bit node[/color]
    Set objLocator = CreateObject("Wbemscripting.SWbemLocator")
    Set objServices = objLocator.ConnectServer(strComputer, "root\default", "", "", , , , objCtx)
    Set objStdRegProv = objServices.Get("StdRegProv")
    
    Set Inparams = objStdRegProv.Methods_("EnumKey").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Set outparams = objStdRegProv.ExecMethod_("EnumKey", Inparams, , objCtx)

    arrSubkeys = outparams.sNames 

    Set Inparams = objStdRegProv.Methods_("GetStringValue").Inparameters
    Inparams.Hdefkey = HKLM
    Inparams.Svaluename = "DisplayName"
    For lp = 0 To UBound(arrSubkeys) - 1
        Inparams.Ssubkeyname = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" & arrSubkeys(lp)
        Set outparams = objStdRegProv.ExecMethod_("GetStringValue", Inparams, , objCtx)
        If InStr(outparams.sValue, "Office") Then MsgBox outparams.sValue
    Next

[/blue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top