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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way , other than..., to see if Word is installed. 1

Status
Not open for further replies.

CFPR

MIS
May 9, 2003
58
0
0
PR
Is there a better way to determine if Word is installed or not and, if so, which version is installed.?

I have the following...it works but I feel is very basic.

x=.f.
on error x=.t.
oWord = CREATEOBJECT('Word.Application')
if x=.t.
messagebox("Word not installed..")
return
endif

I guess I'm ready for some API stuff..Any comments.

Thanks..

CF
 

Another would be if you have a word document, check to see if you find the path of the executable
Code:
DECLARE INTEGER FindExecutable IN shell32; 
    STRING lpFile, STRING lpDir, STRING @lpResult 

lcResult = SPACE(250) 

IF FindExecutable ("c:\mydoc.doc", "", @lcResult) > 32 
    lcResult = ALLTRIM(STRTRAN(lcResult, Chr(0), " ")) 
    ? lcResult 
ELSE 
    DECLARE INTEGER GetLastError IN kernel32 
    ? "Error code:", GetLastError() 
ENDIF

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Here's the CheckServer function Della Martin wrote for our book on Automating Office from VFP:

Code:
* CheckServer.prg
* © 2000, Tamar E. Granor and Della Martin
* From:  Microsoft Office Automation with Visual FoxPro
* Hentzenwerke Publishing. [URL unfurl="true"]www.hentzenwerke.com[/URL]

LPARAMETER cServerName

LOCAL oRegistry, cClassID, cEXEName, lEXEExists, ;
      aClassIDValues, aClassIDValues, aServerNameValues

IF VERSION() = "Visual FoxPro 06"
  oRegistry = NewObject("Registry", HOME() + "FFC\Registry")
ELSE
  SET PROCEDURE TO HOME() + "samples\classes\registry.prg" ADDITIVE
  oRegistry = CreateObject("Registry")
ENDIF

lEXEExists = .F.
DECLARE aClassIDValues[1], aServerNameValues[1]

WITH oRegistry

  * Find the CLSID of the server. First, look for
  * the Class's Key.
  IF .OpenKey(cServerName + "\CLSID") = 0

    * The Class's Key is open, now enumerate its values
    .EnumKeyValues(@aClassIDValues)
    
    * The data portion of the first (only) value returned
    * is the CLSID. Find the LocalServer32 key for the CLSID
    IF .OpenKey("CLSID\" + aClassIDValues[1,2] + "\LocalServer32") = 0

      * Enumerate teh LocalServer32 values
      .EnumKeyValues(@aServerNameValues)
      
      * The EXE file is stored in the first (only) data value returned. 
      cEXEName = aServerNameValues[2]
      
      * The value that's returned may have " -Automation" or " /Automation" or
      * " /AUTOMATION" & other trailing stuff at the end. Strip it off.
      IF "AUTO" $ UPPER(cEXEName)
        cEXEName = LEFT(cEXEName, ATC("AUTO", UPPER(cEXEName)) - 2)
      ENDIF
      
      * Verify that the file exists      
      lEXEExists = FILE(cEXEName)   

    ENDIF     
  ENDIF
ENDWITH

RETURN lEXEExists

Tamar
 
Hi CFPR

In addition to what Tamar and Mike told you, yoou can add some code similar to this line that Tamar gave you:

* The data portion of the first (only) value returned
* is the CLSID. Find the LocalServer32 key for the CLSID
IF .OpenKey("CLSID\" + aClassIDValues[1,2] + "\LocalServer32") = 0

to determine what version of Word is installed. Instead of retrieveing the default data for the LocalServer32 subkey, you need to retrieve the default data for the ProgID subkey. This returns something like Word.Application.11 (Word 2003), Word.Application.10 (Word XP), or Word.Application.9 (Word 2K).



Marcia G. Akins
 
Hi to all and thanks for the feedback. Unfortunately, I do not have enough background on the 'register' and 'class id' options presented by Tamar and Marcia. So..sorry for some basic questions...

When you say servername..that is really the pc name? Also, where in that code does it refer to Word?!? I tried the code locally on my PC and simply got .f. on the return. I basically ran it in a simple .prg running from the ide.

Thanks for any additional guidance you may provide. Also, I did understood well Mike's option though..

Thanks.
CF
 
>> ..that is really the pc name?

Nope, the PC is irrelevant. The "server" is the COM-server you're looking for, i.e. "Word.Application". Thus, that is what you have to pass to Tamar's function (that's your reference to Word, then). So try
Code:
?CheckServer("word.application")

Volker/
 
You can try this:
Code:
? IsClassRegistered("Word.Application")


FUNCTION IsClassRegistered(tcClass)                          

   LOCAL lnKey
   #define HKEY_CLASSES_ROOT    -2147483648
   #define ERROR_SUCCESS	 	0	&& OK

   DECLARE INTEGER RegOpenKey IN Win32API ;
           INTEGER nHKey, STRING @cSubKey, INTEGER @nResult

   DECLARE INTEGER RegCloseKey IN Win32API ;
           INTEGER nHKey

   lnKey    = 0
   llRetVal = (RegOpenKey(HKEY_CLASSES_ROOT, tcClass, @lnKey) = ERROR_SUCCESS)

   IF llRetVal
      RegCloseKey(lnKey)
   ENDIF

RETURN llRetVal

Borislav Borissov
 
Thanks Borislav. That works well! One final point, what code modifications would you recommend that will show which version of Word is installed?

Thanks..

CF
 
Hey Volker.

How are you? Long time no see! Andy and I are in England right now visiting his sister in Wellingborough.

Any chance that we will see you while we are on this side of the pond?



Marcia G. Akins
 
This is not my code, I get it from a UniversalThread unfortuntely I can't remember who post it.
About your Question you can modify the function:
Code:
** If the function returns -1 class is not registered
** If the function returns  0 cannot determine the version
** but the class is registered
** otherwise returns the CurrentVersion of Application
** I tested it ONLY on MicroSoft Word/Excel



? IsClassRegistered("Word.Application")


FUNCTION IsClassRegistered(tcClass)                          

   LOCAL lnKey
   #define HKEY_CLASSES_ROOT    -2147483648
   #define ERROR_SUCCESS         0    && OK

   DECLARE INTEGER RegOpenKey IN Win32API ;
           INTEGER nHKey, STRING @cSubKey, INTEGER @nResult

   DECLARE INTEGER RegCloseKey IN Win32API ;
           INTEGER nHKey

   DECLARE Integer RegQueryValueEx IN Win32API ;
           Integer nHKey, String lpszValueName, Integer dwReserved,;
           Integer @lpdwType, String @lpbData, Integer @lpcbData


   lnKey    = 0
   llRetVal = (RegOpenKey(HKEY_CLASSES_ROOT, tcClass, @lnKey) = ERROR_SUCCESS)

   IF llRetVal
      LOCAL lpdwReserved,lpdwType,lpbData,lpcbData,nErrCode
      STORE 0 TO lpdwReserved,lpdwType
      STORE SPACE(256) TO lpbData
      STORE LEN(m.lpbData) TO m.lpcbData
      lnKeyVer = 0
      llRetVal = (RegOpenKey(HKEY_CLASSES_ROOT, tcClass+"\CurVer", @lnKeyVer) = ERROR_SUCCESS)
      IF llRetVal
         IF RegQueryValueEx(lnKeyVer,"", m.lpdwReserved,@lpdwType,@lpbData,@lpcbData) # ERROR_SUCCESS
            llRetVal = 0
         ELSE
            llRetVal = LEFT(m.lpbData,m.lpcbData-1)
            llRetVal = INT(VAL(SUBSTR(llRetVal,RAT([.],llRetVal)+1)))
         ENDIF
         RegCloseKey(lnKeyVer)
      ELSE
         llRetVal = 0
      ENDIF
      RegCloseKey(lnKey)
   ELSE
      llRetVal = -1
   ENDIF

RETURN llRetVal

Borislav Borissov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top