How to get the PureBasic install directory
Posted: Tue May 06, 2008 9:24 pm
This is a modification of the code used by the Tailbite installer. If PureBasic.exe has not been run yet and the .pb file association has not occurred then the pure Tailbite method will fail.
I've added an additional check which uses the uninstall information for the install directory. Both methods should be used in this order because the install directory may be on a pen drive and not as up to date as the .pb file association.
I've added an additional check which uses the uninstall information for the install directory. Both methods should be used in this order because the install directory may be on a pen drive and not as up to date as the .pb file association.
Code: Select all
Procedure.s GetPBFolder()
MaxStringSize=(#MAX_PATH*2)+2
Value=AllocateMemory(MaxStringSize)
If GetVersion_()&$ff0000 ; Windows NT/XP
If RegOpenKeyEx_(#HKEY_CLASSES_ROOT,"Applications\PureBasic.exe\shell\open\command",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS
If RegQueryValueEx_(hKey,"",0,@Type,Value,@MaxStringSize)=#ERROR_SUCCESS
Folder.s=PeekS(Value)
EndIf
RegCloseKey_(hKey)
EndIf
Else ; The same for Win9x
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"Software\Classes\PureBasic.exe\shell\open\command",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS
If RegQueryValueEx_(hKey,"",0,@Type,Value,@MaxStringSize)=#ERROR_SUCCESS
Folder.s=PeekS(Value)
EndIf
RegCloseKey_(hKey)
EndIf
EndIf
FreeMemory(Value)
Folder.s=RemoveString(Left(Folder.s,FindString(Folder.s,"PureBasic.exe",1)-1),Chr(34))
If Not Folder.s
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Uninstall\PureBasic_is1",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS
If RegQueryValueEx_(hKey,@"InstallLocation",0,@Type,Value,@MaxStringSize)=#ERROR_SUCCESS
Folder.s=PeekS(Value)
EndIf
RegCloseKey_(hKey)
EndIf
EndIf
ProcedureReturn Folder.s
EndProcedure