Announcement

Collapse
No announcement yet.

How can an application detect Word97

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can an application detect Word97

    I have written a program that installs an application, being a so called 'Word-plugin'.
    It would be nice if my prog. could detect if MS-Word97 (internally known as version 8) is
    already pre-installed. This to avoid an unneccessary re-installation.

    Word97 maybe either installed stand alone or as part of an office suite. Does this complicate the matter?

    Thanks for any hint into the right direction.



    ------------------
    mailto:[email protected][email protected]</A>
    www.basicguru.com/zijlema/

    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
    http://zijlema.basicguru.eu
    *** Opinions expressed here are not necessarily untrue ***

  • #2
    Egbert --
    MS Office creates a lot of keys in registry.
    Take a look something like HKEY_LOCAL_MACHINE\Software\Microsoft\Office ...

    ------------------
    E-MAIL: [email protected]

    Comment


    • #3
      Exactly Semen,

      This registry mess is the real problem!

      ------------------
      mailto:[email protected][email protected]</A>
      www.basicguru.com/zijlema/

      Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
      http://zijlema.basicguru.eu
      *** Opinions expressed here are not necessarily untrue ***

      Comment


      • #4
        Egbert,

        The old technique was to use a tool like spy to get the application
        classname so that you can use the function FindWindow() to determine
        if it was running.

        It used to be OPUSAPP on very old versions of word and it may be different
        with the current ones but if you can locate the class name for word, its
        a simple API call to test if its running.

        Code:
          ClassName$ = "Whatever_Its_Name_Is"
          
          retval = FindWindow(StrPtr(ClassName$),ByVal %NULL)
          
              If retval = %NULL Then
                MsgBox "Sorry Dude, Word is not running"
              Else
                MsgBox "Congratulations, Word is running"
              End If
        Regards,

        [email protected]

        ------------------
        hutch at movsd dot com
        The MASM Forum

        www.masm32.com

        Comment


        • #5
          I am not sure how much it will help you, since the detection method I use is for VB and not for PB, but here it is:

          On Error GoTo ErrSub
          'Word'97 and up can still understand these old Word.Basic's
          Set Word = CreateObject("Word.Basic")
          If Val(Word.AppInfo$(2)) >= 8 Then
          'Word'97 or up
          Set Word = Nothing
          Set Word = CreateObject("Word.Application")
          End If

          ErrSub:
          If Err = 429 Then
          'MSWord is not installed
          end if

          Sincerely,


          Peter Redei



          ------------------

          Comment


          • #6
            Steve,

            It's not a matter of 'is the application running?' but is it installed.
            Thanks, nevertheless, for your effort to help me out.

            ------------------
            mailto:[email protected][email protected]</A>
            www.basicguru.com/zijlema/

            Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
            http://zijlema.basicguru.eu
            *** Opinions expressed here are not necessarily untrue ***

            Comment


            • #7
              Egbert -
              If you don't like direct access to registry
              1) create a doc-file (fictive.doc)
              2) FindExecutable "fictive.doc" (retrieving a path for msword.exe)
              3) analyze version info of msword.exe


              ------------------
              E-MAIL: [email protected]

              Comment


              • #8
                I may be missing the point here, but why not just look to see if Winword.exe is on a drive?
                Peter Stephensen posted some very useful code for scanning directories looking for a particular file - thank you Peter, this has got me out of a hole on several occasions.

                I use it to find where a user has put Acrobat Reader and Iexplore.exe.

                POFFS returns the following data for this entry:
                Message 00108 000489.html
                Author Peter Stephensen
                Title Scan directories
                Date March 16 2000

                Hope this is of help
                Iain Johnstone

                ------------------
                “None but those who have experienced them can conceive of the enticements of science” - Mary Shelley

                Comment


                • #9
                  Semen,

                  You are great! Thank you. This is what you mean, is'nt it?
                  Code:
                  #COMPILE EXE
                  #INCLUDE "WIN32API.INC"
                    
                  FUNCTION Word97Exist(szFileName AS ASCIIZ * %MAX_PATH) AS LONG
                    LOCAL Buffer AS STRING, ParsedFileName AS STRING, BuffSize AS LONG, ret AS LONG
                    LOCAL ffi AS VS_FIXEDFILEINFO PTR
                   
                    FUNCTION = %FALSE
                    ret = FindExecutable("Focus.doc", "", szFileName)
                    IF ret < 33 THEN EXIT FUNCTION                      ' error
                    ParsedFileName = DIR$(szFileName)
                    IF UCASE$(ParsedFileName) <> "WINWORD.EXE" THEN EXIT FUNCTION
                    BuffSize = GetFileVersionInfoSize(szFileName, 0&)
                    IF BuffSize = 0 THEN EXIT FUNCTION                  ' no such info
                    Buffer = SPACE$(BuffSize)
                    ret = GetFileVersionInfo(szFileName, 0&, BuffSize, BYVAL STRPTR(Buffer))
                    IF ret = 0 THEN EXIT FUNCTION                       ' error
                    ret = VerQueryValue(BYVAL STRPTR(Buffer), "\", BYVAL VARPTR(ffi), s&)
                    IF ret = 0 THEN EXIT FUNCTION                       ' error
                    FUNCTION = HIWRD(@ffi.dwFileVersionMS)
                  END FUNCTION
                   
                  FUNCTION PBMain() AS LONG
                    LOCAL ret AS LONG, icon AS LONG
                    LOCAL msgText AS STRING, szPath AS ASCIIZ * %MAX_PATH, fName AS STRING
                    
                    ret = Word97Exist(szPath)
                    IF ret THEN
                      fName = DIR$(szPath)
                      REPLACE fName WITH "" IN szPath
                      szPath = LEFT$(szPath, LEN(szPath) - 1)
                      msgText = fName + " can be found in this directory: " + $CRLF + _
                                CHR$(34) + szPath + CHR$(34) + $CRLF + _
                                "It is version " + FORMAT$(ret)
                      IF ret = 8 THEN msgText = msgText + ", also referred to as Word97"
                      icon = 64
                    ELSE
                      msgText = "Microsoft Word not found"
                      icon = 16
                    END IF
                    MSGBOX msgText, icon, "Searching MS-Word"
                  END FUNCTION

                  ------------------
                  mailto:[email protected][email protected]</A>
                  www.basicguru.com/zijlema/



                  [This message has been edited by Egbert Zijlema (edited November 17, 2000).]

                  Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                  http://zijlema.basicguru.eu
                  *** Opinions expressed here are not necessarily untrue ***

                  Comment


                  • #10
                    Semen,

                    Forgot one important thing: the associated executable for .doc-files might be Word Perfect.
                    If that happens to be the case and its version is 8, MS-Word will not be installed, because
                    the program assumes it has been pre-installed. So we have to check for the file name as well
                    (see edited message with source).

                    ------------------
                    mailto:[email protected][email protected]</A>
                    www.basicguru.com/zijlema/

                    Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                    http://zijlema.basicguru.eu
                    *** Opinions expressed here are not necessarily untrue ***

                    Comment


                    • #11
                      Egbert --
                      I agree that it's necessary to check a name (WordPad, for example, could be linked with .DOC also).
                      But if name is wrong, perhaps, it's necessary to check DOT.


                      ------------------
                      E-MAIL: [email protected]

                      Comment


                      • #12
                        If you take a closer look to the .DOC registered, you know the entry "Word.Document.8" as you already said.
                        This is the registry entry below..
                        \Word.Document.8 contains the entry:

                        shell\open\command wich contains:
                        ""C:\Program Files\Microsoft Office\Office\Winword.exe" /n

                        So now we have the path..
                        In this path we have 2 files:
                        WINWORD8.SRG
                        WINWORD.EXE

                        Take a look to the first 2 sentences of WINWORD8.SRG.

                        And you know the fileversion of course, use it on winword.exe:

                        a d e m a r k o f M i c r o s o f t C o r p o r a t i o n .
                        g a l T r a d e m a r k s 2 W i n d o w s « i s a r e g i s
                        t r a d e m a r k o f M i c r o s o f t C o r p o r a t i o n
                        O r i g i n a l F i l e n a m e W I N W O R D . E X E `  P r
                        a m e M i c r o s o f t « W o r d f o r W i n d o w s «
                        >> P r o d u c t V e r s i o n 8 . 0 D  V a r F i l e I n f o
                        a n s l a t i o n õ

                        Is this ok?



                        ------------------
                        [email protected]
                        hellobasic

                        Comment


                        • #13
                          Edwin,
                          You're even better than Semen!
                          Is this what you mean (approximately)?
                          Code:
                          #COMPILE EXE
                          #INCLUDE "WIN32API.INC"
                           
                          FUNCTION Word97Exist() AS LONG
                            LOCAL hKey AS LONG, ret AS LONG, szBuffer AS ASCIIZ * %MAX_PATH
                            FUNCTION = %FALSE
                            IF RegOpenKeyEx(%HKEY_CLASSES_ROOT, ".DOC", 0, %KEY_ALL_ACCESS, hKey) <> %ERROR_SUCCESS THEN
                              EXIT FUNCTION
                            END IF
                           
                            ret = RegQueryValueEx(hKey, "", 0, 0, szBuffer, SIZEOF(szBuffer))
                            IF (ret <> %ERROR_SUCCESS) OR (LEN(szBuffer) = 0) THEN
                              RegCloseKey hKey
                              EXIT FUNCTION
                            END IF
                            IF szBuffer = "Word.Document.8" THEN FUNCTION = %TRUE
                            RegCloseKey hKey
                          END FUNCTION
                           
                          FUNCTION PBMain() AS LONG
                            IF Word97Exist THEN
                              MSGBOX "You're lucky, Word97 has been installed on this machine.", 64, "Bingo!"
                            ELSE
                              MSGBOX "Sorry, but you have to install Word97 yourself.", 16, "Not found"
                            END IF
                          END FUNCTION
                          Thank you,

                          ------------------
                          mailto:[email protected][email protected]</A>
                          www.basicguru.com/zijlema/

                          [This message has been edited by Egbert Zijlema (edited November 17, 2000).]

                          Egbert Zijlema, journalist and programmer (zijlema at basicguru dot eu)
                          http://zijlema.basicguru.eu
                          *** Opinions expressed here are not necessarily untrue ***

                          Comment


                          • #14
                            My bet would be to do the following...

                            (1a) Check if WINWORD.EXE is in it's default location
                            or
                            (1b) Search for WINWORD.EXE if it's NOT in the default location

                            (2) Read the Version stamp of the found WINWORD.EXE itself.

                            ------------------
                            George W. Bleck
                            Senior System Engineer
                            KeySpan Corporation
                            <b>George W. Bleck</b>
                            <img src='http://www.blecktech.com/myemail.gif'>

                            Comment


                            • #15
                              Egbert,

                              In fact, this is what i meant.

                              1) Retrieve the full path and filename.
                              2) Use the fileversion for correct version.
                              3) Distinguish different type of applications like Word or WP etc..

                              Is this ok?

                              Code:
                              #Compile Exe
                              #Include "WIN32API.INC"
                               
                              Function Reg_GetAppByExtension( ByVal Extension As String ) As String
                               
                                  Dim a           As Long
                                  Dim hKey        As Long
                                  Dim Result      As Long
                                  Dim Buffer      As Asciiz * %MAX_PATH + 1
                                  Dim GroupName   As String
                               
                                  Extension = Trim$( Extension )
                                  If Extension = "" Then Exit Function
                                  Extension = "." & Ltrim$( Extension, "." )
                               
                                  '// Find the application using this extension..
                                  If RegOpenKeyEx( _
                                        %HKEY_CLASSES_ROOT _
                                      , ByVal StrPtr( Extension ) _
                                      , 0 _
                                      , %KEY_QUERY_VALUE _
                                      , hKey _
                                      ) <> %ERROR_SUCCESS Then Exit Function
                               
                                  If RegQueryValueEx( _
                                                hKey _
                                              , ByVal 0& _
                                              , ByVal 0& _
                                              , ByVal 0& _
                                              , Buffer _
                                              , SizeOf( Buffer ) _
                                              ) = %ERROR_SUCCESS _
                                              Then GroupName = Buffer
                               
                                  RegCloseKey hKey
                               
                                  '// Let's open the groupname.
                                  If GroupName = "" Then Exit Function
                               
                                  GroupName = GroupName & "\shell\open\command"
                               
                                  If RegOpenKeyEx( _
                                        %HKEY_CLASSES_ROOT _
                                      , ByVal StrPtr( GroupName ) _
                                      , 0 _
                                      , %KEY_QUERY_VALUE _
                                      , hKey _
                                      ) <> %ERROR_SUCCESS Then Exit Function
                               
                                  If RegQueryValueEx( _
                                                hKey _
                                              , ByVal 0& _
                                              , ByVal 0& _
                                              , ByVal 0& _
                                              , Buffer _
                                              , SizeOf( Buffer ) _
                                              ) = %ERROR_SUCCESS _
                                              Then GroupName = Buffer
                               
                               
                                  RegCloseKey hKey
                               
                                  Buffer = Trim$( Buffer )
                               
                                  '// is it a long file name?
                                  If Left$( Buffer, 1 ) = Chr$( 34 ) Then
                               
                                      Buffer = Mid$( Buffer, 2 )
                                      a = Instr( Buffer, Chr$( 34 ) )
                                      If a Then Buffer = Left$( Buffer, a - 1 )
                               
                                  Else
                               
                                      '// Short name without spaces, remove parameters.
                                      a = Instr( Buffer, " " )
                                      If a Then Buffer = Left$( Buffer, a - 1 )
                               
                                  End If
                               
                                  Function = Buffer
                               
                              End Function
                               
                              Function IsSufficientWordVersion( ByVal FileName As String ) As Long
                               
                                  Dim a                   As Long
                                  Dim BufLen              As Long
                                  Dim Buffer              As String
                                  Dim AppName             As String
                                  Dim FileVersion         As VS_FIXEDFILEINFO Ptr
                                  Dim fvHandle            As Long
                                  Dim MajorVersion        As Long
                                  Dim MinorVersion        As Long
                                  Dim RevisionVersion     As Long
                                  Dim ResRevisionVersion  As Long
                               
                                  FileName = Trim$( FileName )
                                  If FileName = "" Then Exit Function
                               
                                  AppName = FileName
                                  a = Instr( -1, AppName, "\" )
                                  If a Then AppName = Mid$( AppName, a + 1 )
                               
                                  '// Determine fileinfo size.
                                  BufLen = GetFileVersionInfoSize( ByVal StrPtr( FileName ), fvHandle )
                                  If BufLen =< 0 Then Exit Function
                               
                                  '// Prepare buffer
                                  Buffer = String$( BufLen, 0 )
                               
                                  '// Retrieve fileinfo.
                                  a = GetFileVersionInfo( ByVal StrPtr( FileName ), ByVal 0&, BufLen, ByVal StrPtr( Buffer ) )
                                  If a = 0 Then Exit Function
                               
                                  '// Retrieve the fileversion.
                                  VerQueryValue ByVal StrPtr( Buffer ), "\", FileVersion, fvHandle
                                  MajorVersion        = @FileVersion.dwFileVersionMS   \ &HFFFF&
                                  MinorVersion        = @FileVersion.dwFileVersionMS And &HFFFF&
                                  RevisionVersion     = @FileVersion.dwFileVersionLS   \ &HFFFF&
                                  ResRevisionVersion  = @FileVersion.dwFileVersionLS And &HFFFF&
                               
                              #If 1   '< Set to 0 to skip..
                               
                                  MsgBox AppName  _
                                      & Str$( MajorVersion ) & "," _
                                      & Str$( MinorVersion ) & "," _
                                      & Str$( RevisionVersion ) & "," _
                                      & Str$( ResRevisionVersion ) _
                                      , %MB_TASKMODAL, "FileVersion"
                               
                              #EndIf
                               
                                  '// Check per application.
                                  Select Case UCase$( AppName )
                                  Case "WINWORD.EXE"
                               
                                      Function = IsTrue( MajorVersion >= 8 )
                               
                                  Case "WP6.EXE"  '<< Don't know this one  
                                  Case Else
                                  End Select
                               
                              End Function
                               
                              Function PbMain() As Long
                               
                                  Dim T As String
                               
                                  T = Reg_GetAppByExtension( "DOC" )
                                  MsgBox T & $CRLF & Str$( IsSufficientWordVersion( T ) ), %MB_TASKMODAL, "Word"
                               
                              End Function

                              ------------------
                              [email protected]
                              hellobasic

                              Comment


                              • #16
                                Egbert,

                                What was wrong with Semens original solution,

                                You know that if you are looking for "Word 97" it is going to appear in

                                HKEY_LOCAL_MACHINE\Software\Microsoft\Office\8.0\Word\InstallRoot

                                Look for the key 'Path' and if it has been installed the Path to the
                                executable will be returned. (I agree it is a mess though, some programs
                                return the path with the exename others without, some enclosed with
                                qoutation marks, others without etc.)

                                What am I missing.

                                Trevor

                                ------------------

                                Comment


                                • #17
                                  What if the key changes?
                                  You applied a specific word97 key.
                                  Maybe the question is not if you have Word97 but if the has Word97 or higher.
                                  The code i placed does not refer in any way to a specific word version.
                                  Only at the end for testing..

                                  Additionally i wrote a case in case you want to accept wp users too.

                                  BTW, as mentioned earlier, FindExecutable is a prob. a good shortcut for the registry part.
                                  This makes it very small and you perfectly know the exact version of the exe used.





                                  ------------------
                                  [email protected]
                                  hellobasic

                                  Comment

                                  Working...
                                  X