Here are my most recent changes to this function and also the function I use to find the PureBasic application data directory. These commands should now be Vista-compatible.
Code: Select all
Procedure.s GetPBFolder()
Protected hKey.l, Type.l, Res.l, Folder.s, lpData.l, cbData.l, OS.s, Key.s, PBRegKey.s
Res=-1
Select OSVersion()
Case #PB_OS_Windows_95,#PB_OS_Windows_98,#PB_OS_Windows_ME
OS.s = "Detected OS : Windows 95/98/ME"
PBRegKey.s = "Software\Classes\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, PBRegKey, 0, #KEY_ALL_ACCESS, @hKey)
Case #PB_OS_Windows_NT3_51,#PB_OS_Windows_NT_4,#PB_OS_Windows_2000,#PB_OS_Windows_XP,#PB_OS_Windows_Server_2003
OS.s = "Detected OS : Windows NT/2000/XP"
PBRegKey.s = "Applications\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_CLASSES_ROOT, PBRegKey, 0, #KEY_ALL_ACCESS, @hKey)
Case #PB_OS_Windows_Vista,#PB_OS_Windows_Server_2008,#PB_OS_Windows_Future
OS.s = "Detected OS : Windows Vista/Server 2008"
PBRegKey.s = "Software\Classes\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_CURRENT_USER, PBRegKey, 0, #KEY_ALL_ACCESS , @hKey)
EndSelect
If Not RegQueryValueEx_(hKey,0,0,0,0,@Size)=#ERROR_SUCCESS Or Not Size
ProcedureReturn ""
EndIf
lpData=AllocateMemory(Size)
If Res=#ERROR_SUCCESS And hKey
If RegQueryValueEx_(hKey,"",0,0,lpData,@Size)=#ERROR_SUCCESS
Folder.s=PeekS(lpData)
Folder.s=GetPathPart(StringField(Folder.s,2,Chr(34)))
EndIf
RegCloseKey_(hKey)
EndIf
If lpData
FreeMemory(lpData)
lpData=0
EndIf
; Backup
If Not Folder.s
If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,"Software\Microsoft\Windows\CurrentVersion\Uninstall\PureBasic_is1",0,#KEY_ALL_ACCESS,@hKey)=#ERROR_SUCCESS
If Not RegQueryValueEx_(hKey,"InstallLocation",0,0,0,@Size)=#ERROR_SUCCESS Or Not Size
ProcedureReturn ""
EndIf
lpData=AllocateMemory(Size)
If Not RegQueryValueEx_(hKey,"InstallLocation",0,0,lpData,@Size)=#ERROR_SUCCESS
ProcedureReturn ""
EndIf
Folder.s=PeekS(lpData)
If lpData
FreeMemory(lpData)
lpData=0
EndIf
RegCloseKey_(hKey)
EndIf
EndIf
ProcedureReturn Folder.s
EndProcedure
Procedure.s GetPBAppFolder()
Protected hKey.l,Type.l,Res.l,Folder.s,lpData.l,cbData.l,OS.s,Key.s,PBRegKey.s
Res = -1
Select OSVersion()
Case #PB_OS_Windows_95,#PB_OS_Windows_98,#PB_OS_Windows_ME
OS.s = "Detected OS : Windows 95/98/ME"
PBRegKey.s = "Software\Classes\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE,PBRegKey.s,0,#KEY_ALL_ACCESS,@hKey)
Case #PB_OS_Windows_NT3_51,#PB_OS_Windows_NT_4,#PB_OS_Windows_2000,#PB_OS_Windows_XP,#PB_OS_Windows_Server_2003
OS.s = "Detected OS : Windows NT/2000/XP"
PBRegKey.s = "Applications\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_CLASSES_ROOT,PBRegKey.s,0,#KEY_ALL_ACCESS,@hKey)
Case #PB_OS_Windows_Vista,#PB_OS_Windows_Server_2008,#PB_OS_Windows_Future
OS.s = "Detected OS : Windows Vista/Server 2008"
PBRegKey.s = "Software\Classes\PureBasic.exe\shell\open\command"
Res = RegOpenKeyEx_(#HKEY_CURRENT_USER,PBRegKey.s,0,#KEY_ALL_ACCESS ,@hKey)
EndSelect
If Not RegQueryValueEx_(hKey,0,0,0,0,@Size)=#ERROR_SUCCESS Or Not Size
ProcedureReturn ""
EndIf
lpData=AllocateMemory(Size)
If Res = #ERROR_SUCCESS And hKey
If RegQueryValueEx_(hKey,"",0,@Type,lpData,@Size)=#ERROR_SUCCESS
Folder.s=PeekS(lpData)
EndIf
RegCloseKey_(hKey)
EndIf
If lpData
FreeMemory(lpData)
lpData=0
EndIf
If Folder.s
Folder.s=RemoveString(Folder.s,Left(Folder.s,FindString(Folder.s,"/A",1)-1),1)
Folder.s=RemoveString(Folder.s,Left(Folder.s,FindString(Folder.s,Chr(34),1)),1)
Folder.s=Left(Folder.s,FindString(Folder.s,Chr(34),1)-1)
For i=1 To Len(Folder.s)
If FindString(Folder.s,"\",i)
lastfound=i
EndIf
Next i
If lastfound
Folder.s=Left(Folder.s,lastfound)
EndIf
Else
; Backup
If SHGetSpecialFolderLocation_(#Null,#CSIDL_APPDATA,@pidl)=#ERROR_SUCCESS
Location.s=Space(#MAX_PATH)
If SHGetPathFromIDList_(pidl,@Location.s)
If Not Right(Location.s,1)="\"
Location.s+"\"
EndIf
EndIf
If pidl
CoTaskMemFree_(pidl) ; Instead of messing with com imalloc free and whatnot.
EndIf
Folder.s=Location.s+"PureBasic\"
If Not FileSize(Folder.s)=-2
Folder.s=""
EndIf
EndIf
EndIf
ProcedureReturn Folder.s
EndProcedure
Debug GetPBFolder()
Debug GetPBAppFolder()