emendelson

Detect whether Microsoft Word is installed?

4 posts in this topic

#1 ·  Posted

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?

Share this post


Link to post
Share on other sites



#2 ·  Posted

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)

 

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

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.

Share this post


Link to post
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