Code: Select all
Procedure.s RegRead(Root, KeyPath.s, ValueName.s)
Protected valueData.s, hKey, size, type
If #ERROR_SUCCESS = RegOpenKeyEx_(Root, KeyPath, 0, #KEY_READ, @hKey) ; open with READ access rights
If #ERROR_SUCCESS = RegQueryValueEx_(hKey, ValueName, 0, @type, 0, @size) ; get type and size
ValueData = Space(size) ; alloc memory
If #ERROR_SUCCESS = RegQueryValueEx_(hKey, ValueName, 0, 0, @valueData, @size) ; get data to return
EndIf
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn valueData ; return the result
EndProcedure
Debug RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\16.0\Excel\InstallRoot","Path")Tried with #HKEY_CURRENT_USER:
Code: Select all
Procedure.s RegRead(Root, KeyPath.s, ValueName.s)
Protected valueData.s, hKey, size, type
If #ERROR_SUCCESS = RegOpenKeyEx_(Root, KeyPath, 0, #KEY_READ, @hKey) ; open with READ access rights
If #ERROR_SUCCESS = RegQueryValueEx_(hKey, ValueName, 0, @type, 0, @size) ; get type and size
ValueData = Space(size) ; alloc memory
If #ERROR_SUCCESS = RegQueryValueEx_(hKey, ValueName, 0, 0, @valueData, @size) ; get data to return
EndIf
EndIf
RegCloseKey_(hKey)
EndIf
ProcedureReturn valueData ; return the result
EndProcedure
Debug RegRead(#HKEY_CURRENT_USER,"SOFTWARE\Microsoft\Office\16.0\Excel","ExcelName")My point is to do a check like:
Code: Select all
Procedure.s IsExcelInstalled()
ExcelApp.s = RegRead(#HKEY_CLASSES_ROOT,"Excel.Application\CurVer","")
If ExcelApp = ""
ProcedureReturn "No Excel found"; no version found
Else;check which version
If RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\16.0\Excel\InstallRoot","Path") <> ""
ProcedureReturn "Excel 2016/2019/2021 found"
ElseIf RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\15.0\Excel\InstallRoot","Path") <> ""
ProcedureReturn "Excel 2013 found"
ElseIf RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\14.0\Excel\InstallRoot","Path") <> ""
ProcedureReturn "Excel 2010 found"
ElseIf RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\12.0\Excel\InstallRoot","Path") <> ""
ProcedureReturn "Excel 2007 found"
ElseIf RegRead(#HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Office\11.0\Excel\InstallRoot","Path") <> ""
ProcedureReturn "Excel 2003 found"
Else
ProcedureReturn "Excel older than 2003 found"
EndIf
EndIf
EndProcedureAny better implementation?

