Determine the SpiderBasic installation path
Posted: Sat Nov 29, 2025 10:06 pm
Hello! To determine the installation path of PureBasic, we have #PB_Compiler_Home.
My question is: in PureBasic, is there any way to determine the installation path of SpiderBasic, other than specifying it manually or looking it up in the registry using the following example:
My question is: in PureBasic, is there any way to determine the installation path of SpiderBasic, other than specifying it manually or looking it up in the registry using the following example:
Code: Select all
Procedure.s _GetSpiderBasicPath()
Protected path.s = "", hKey, type, size
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\SpiderBasic_is1", 0, #KEY_READ, @hKey) = #ERROR_SUCCESS
If RegQueryValueEx_(hKey, "InstallLocation", 0, @type, 0, @size) = #ERROR_SUCCESS And type = #REG_SZ
path = Space(size)
RegQueryValueEx_(hKey, "InstallLocation", 0, 0, @path, @size)
path = Left(path, Len(path) - 1)
EndIf
RegCloseKey_(hKey)
EndIf
; If not found, try an alternative key
If path = "" And RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\SpiderBasic_is1", 0, #KEY_READ, @hKey) = #ERROR_SUCCESS
If RegQueryValueEx_(hKey, "InstallLocation", 0, @type, 0, @size) = #ERROR_SUCCESS And type = #REG_SZ
path = Space(size)
RegQueryValueEx_(hKey, "InstallLocation", 0, 0, @path, @size)
path = Left(path, Len(path) - 1)
EndIf
RegCloseKey_(hKey)
EndIf
If FileSize(path + "SpiderBasic.exe")
ProcedureReturn path
EndIf
ProcedureReturn ""
EndProcedure
Procedure.s _FindSpiderBasicInCommonPaths()
Protected path.s
Dim commonPaths.s(5)
commonPaths(0) = "C:\Program Files\SpiderBasic\"
commonPaths(1) = "C:\Program Files (x86)\SpiderBasic\"
commonPaths(2) = GetEnvironmentVariable("ProgramFiles") + "\SpiderBasic\"
commonPaths(3) = GetEnvironmentVariable("ProgramFiles(x86)") + "\SpiderBasic\"
commonPaths(4) = GetUserDirectory(#PB_Directory_Programs) + "SpiderBasic\"
commonPaths(5) = "D:\Program Files\SpiderBasic\" ; If installed on another drive
For i = 0 To ArraySize(commonPaths()) - 1
If FileSize(commonPaths(i) + "SpiderBasic.exe") >= 0 Or
FileSize(commonPaths(i) + "Compiler\SpiderBasic.exe") >= 0
path = commonPaths(i)
Break
EndIf
Next
ProcedureReturn path
EndProcedure
; Basic function to get SpiderBasic path
Procedure.s GetSpiderBasicHome()
; First we try the registry
Protected path.s = _GetSpiderBasicPath()
; If not found in the registry, look in standard paths
If path = ""
path = _FindSpiderBasicInCommonPaths()
EndIf
; If you found a path, but there is no slash at the end, add it
If path <> "" And Right(path, 1) <> "\"
path + "\"
EndIf
ProcedureReturn path
EndProcedure
; Usage example
CompilerIf #PB_Compiler_IsMainFile
SpiderBasicPath.s = GetSpiderBasicHome()
If SpiderBasicPath <> ""
MessageRequester("SpiderBasic Path", "SpiderBasic installed in:" + #CRLF$ + SpiderBasicPath)
Else
MessageRequester("SpiderBasic Path", "SpiderBasic not found on the system")
EndIf
CompilerEndIf