判别你的机子上是否已安装了 MS Office (MS Outlook、MS Word、MS Excel)
Clear
ckey = "Software\Microsoft\Windows\CurrentVersion\App Paths\outlook.exe"
OutlookExists = readregstring(-2147483646, ckey, "path")
ckey = "Software\Microsoft\Windows\CurrentVersion\App Paths\winword.exe"
WinWordExists = readregstring(-2147483646, ckey, "path")
ckey = "Software\Microsoft\Windows\CurrentVersion\App Paths\excel.exe"
ExcelExists = readregstring(-2147483646, ckey, "path")
? Iif(!Empty(Nvl(OutlookExists,"")), "已安装 MS Outlook", "未安装 MS Outlook")
? Iif(!Empty(Nvl(WinWordExists,"")), "已安装 MS Word", "未安装 MS Word")
? Iif(!Empty(Nvl(ExcelExists,"")), "已安装 MS Excel", "未安装 MS Excel")
Function ReadRegString
***----------------------------------------------------------------------
*** Function: Reads a string value from the registry.
*** Pass: tnHKEY - HKEY value (in CGIServ.h)
*** tcSubkey - The Registry subkey value
*** tcEntry - The actual Key to retrieve
*** Return: Registry String or .NULL. on error
***----------------------------------------------------------------------
Lparameters tnHKey, tcSubkey, tcEntry
Local lnRegHandle, lnResult, lnSize, lcDataBuffer, tnType
tnHKey=Iif(Type("tnHKey")="N",tnHKey,This.HKEY_LOCAL_MACHINE)
lnRegHandle=0
Do DeclareInit && Declare WinAPI function. You only have to do this once.
*** Open the registry key
lnResult=RegOpenKey(tnHKey,tcSubKey,@lnRegHandle)
If lnResult # 0
Return .Null.
Endif
*** Need to define here specifically for Return Type
*** for lpdData parameter or VFP will choke.
*** Here it's STRING.
Declare Integer RegQueryValueEx ;
IN Win32API As RegQueryString;
INTEGER nHKey,;
STRING lpszValueName,;
INTEGER dwReserved,;
INTEGER @lpdwType,;
STRING @lpbData,;
INTEGER @lpcbData
*** Return buffer to receive value
lcDataBuffer=Space(256)
lnSize=Len(lcDataBuffer)
lnType=0
lnResult=RegQueryString(lnRegHandle,tcEntry,0,@lnType,;
@lcDataBuffer,@lnSize)
=RegCloseKey(lnRegHandle)
If lnResult # 0
Return .Null.
Endif
If lnSize<2
Return ""
Endif
*** Return string based on length returned
Return Substr(lcDataBuffer,1,lnSize-1)
Endfunc
*!*
And the DeclareInit function that is called:
Function DeclareInit
*** Open a registry key
Declare Integer RegOpenKey ;
IN Win32API ;
INTEGER nHKey,;
STRING cSubKey,;
INTEGER @nHandle
*** Close an open registry key
Declare Integer RegCloseKey ;
IN Win32API ;
INTEGER nHKey
Endfunc