Jump to content

Detect whether Microsoft Word is installed?


Recommended Posts

Over at CodeProject.com, someone posted this C++ code for testing whether Word is installed:

Type officeType = Type.GetTypeFromProgID("Word.Application");

if (officeType == null)
{
    // Word is not installed.
    // Show message or alert that Word is not installed.
}
else
{
    // Word is installed.
    // Continue your work.
}

I've been trying to figure out to do this in AutoIt, preferably using the COM interface, but I haven't managed at all. Does anyone know the quick answer to this problem?

Link to comment
Share on other sites

Local $oWord = ObjCreate("Word.Application")

If IsObj($oWord) then
    ConsoleWrite ("ObjCreate: Version: " & $oWord.Caption & " " & $oWord.Version & " & Build: " & $oWord.Build & @LF)
    $oWord.Quit
EndIf

ConsoleWrite("RegRead: " & RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe", "Path") & @LF)

 

Link to comment
Share on other sites

Normally use '' for InunoTaishou second solution like so:

$hOffice = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe", "")
If FileExists($hOffice) = 0 Then Exit

However if you're coding for multiple versions of Office I normally  use this:

$hOffice_Version = 0
$hOffice = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe", "")
If FileExists($hOffice) Then $hOffice_Version = Round(FileGetVersion($hOffice), 0)
Switch $hOffice_Version
    Case 12
        ;~ Office 2007 Code here
    Case 14
        ;~ Office 2010 Code here
    Case 15
        ;~ Office 2013 Code here
    Case 16
        ;~ Office 2016 Code here
    Case Else
        ;~ Office not detected or unknown version
EndSwitch

 

Link to comment
Share on other sites

6 hours ago, Subz said:

Normally use '' for InunoTaishou second solution like so:

$hOffice = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe", "")
If FileExists($hOffice) = 0 Then Exit

However if you're coding for multiple versions of Office I normally  use this:

$hOffice_Version = 0
$hOffice = RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe", "")
If FileExists($hOffice) Then $hOffice_Version = Round(FileGetVersion($hOffice), 0)
Switch $hOffice_Version
    Case 12
        ;~ Office 2007 Code here
    Case 14
        ;~ Office 2010 Code here
    Case 15
        ;~ Office 2013 Code here
    Case 16
        ;~ Office 2016 Code here
    Case Else
        ;~ Office not detected or unknown version
EndSwitch

 

That's very useful - thank you.  The second one shows me how to test for ancient versions that may not work with the procedures I'm using. Thank you again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...