Find both Program Files paths on 64bit OS
Posted: Fri Dec 09, 2011 1:36 am
I made a little 32bit exe to collect the two program files paths on Win 64bit OS (Tested on Win7), 'Program Files' and 'Program Files (x86)'. Although many countries just use the US-English folder names, some very significant ones do not. Now, I thought this would work:
....but it returns 'Program Files (x86)' in both cases. Perhaps because the exe itself is 32bit? It seems strange. The exe only queries #CSIDL_PROGRAM_FILESX86 if the OS has been verified as 64bit, so I thought that would be bullet proof......... 
Code: Select all
Procedure.s GetSysFolder(iVal.i)
;-------------------------------
#CSIDL_PROGRAM_FILES = $26 ;C:\Program Files
#CSIDL_PROGRAM_FILESX86 = $2A ;32bit C:\Program Files (x86) on 64bit
Protected iFolderID.i, iSlashTotal.i, iSlashPosn.i, sSpecialFolderLocation.s
If SHGetSpecialFolderLocation_(0, iVal, @iFolderID) = 0
sSpecialFolderLocation = Space(#MAX_PATH)
SHGetPathFromIDList_(iFolderID, @sSpecialFolderLocation)
If sSpecialFolderLocation
If Right(sSpecialFolderLocation, 1) <> "\"
sSpecialFolderLocation + "\"
EndIf
;Double backslashes:
iSlashTotal.i = CountString(sSpecialFolderLocation, "\")
iSlashPosn.i = 1
For i = 1 To iSlashTotal
iSlashPosn = FindString(sSpecialFolderLocation, "\", iSlashPosn)
sSpecialFolderLocation = InsertString(sSpecialFolderLocation, "\", iSlashPosn)
iSlashPosn = iSlashPosn + 2
Next
EndIf
CoTaskMemFree_(iFolderID)
EndIf
ProcedureReturn sSpecialFolderLocation
EndProcedure