Samselvaprabu
Samselvaprabu

Reputation: 18147

How to find whether 64 bit or 32 bit excel is installed via Powershell?

We have written powershell function to find whether 64 bit or 32 bit msi is installed. We are checking outlook registry key as that is the one having bitness information.

But when user is installing only excel without outlook ,this registry key is not reliable( In 64 bit OS it is available but in 32 bit OS it is not available).

Following is the function we wrote to find that. Now as registry key is not available it is not working . is there any other way we can find the bitness of excel ?

Function Get-OfficeVersionInstalled
{
    $NoExcelInstalled = '0'
    $excelApplicationRegKey = "HKLM:\SOFTWARE\Classes\Excel.Application\CurVer"
    if( Test-Path $excelApplicationRegKey)
    {
        $excelApplicationCurrentVersion = (Get-ItemProperty $excelApplicationRegKey).'(default)'

        #Get version number alone from registry value
        $($excelApplicationCurrentVersion -replace "Excel.Application.","")
    }
    else
    {
        $NoExcelInstalled
    }
}

Function Test-Excel2013AndAbove
{
    Param
    (
        [ValidateSet("x64", "x86")]
        $Edition="x64"  
    )
    $isExpectedEditionInstalled = $false
    $officeVersion = Get-OfficeVersionInstalled
    $office2013Version = 15

    if( $officeVersion -ge $office2013Version) {

    # In registry, version will be with decimal
        $officeVersion = $officeVersion+".0"

        # Outlook key is having bitness which will decide the edition. 
    # Even if outlook is not installed this key will be present.
    # This is the only place where we can reliably find the edition of Excel
        $OutlookKey = "HKLM:\SOFTWARE\Microsoft\Office\$officeVersion\Outlook"
        $OutlookWow6432NodeKey = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Office\$officeVersion\Outlook"

        if(Test-Path $OutlookKey)
        {       
            $officeRegKey = $OutlookKey
        }
        else
        {        
            $officeRegKey = $OutlookWow6432NodeKey
        }

        $BitNess = (Get-ItemProperty $officeRegKey).BitNess

        if($BitNess -eq $Edition)
        {
            $isExpectedEditionInstalled = $true
        }
        else
        {
            $isExpectedEditionInstalled = $false
        }

    }

    return $isExpectedEditionInstalled
}

Upvotes: 2

Views: 4068

Answers (2)

M--
M--

Reputation: 28850

I suppose you can simply check the platform from Office\ClickToRun\Configuration:

$officeCheck = 
(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration").platform

if($officeCheck -eq 'x86'){
    # 32-bit office is installed
    }
else{
    # 64-bit office is installed
}

Upvotes: 0

Robert Columbia
Robert Columbia

Reputation: 6418

You cannot run 64 bit software on a 32 bit version of Windows without an emulator (Is there any way to execute 64-bit programs on a 32-bit computer?). This would mean that if you detect a 32 bit OS, any local, non-emulated installation of Excel (if any) would be 32 bit.

So here's some pseudocode to do this:

if (OS.BitSize == 32)
{
    Check if Excel installed. If so, then it is 32 bit.
}
else
{
    //64 bit OS
    Check registry key to determine whether 32 or 64 bit Excel is installed.
}

Upvotes: 2

Related Questions