Getting the Program Files path


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: Getting the Program Files path

  1. #1
    James Brown Guest

    Getting the Program Files path

    Hi,

    I'm using the SHGetSpecialFolderLocation API call to get the location of the
    user's Program Files path. I'm calling CSIDL 38. This works fine on
    Win2000 but it doesn't appear to work on any of the Win98 machines in the
    office - they all return nothing. Is there a way that will work on both
    O/Ss? I've included my module code below the signature, in case I'm doing
    something wrong.

    --
    Regards,

    Jamie Brown, Software Developer
    InfoComp Ltd
    E-Mail: james@infocomp.co.uk
    URL: http://www.infocomp.co.uk

    ************* BEGIN CODE **************

    Option Explicit
    Public Const fgs_FAVORITES As Long = &H6
    Public Const fgs_DESKTOP As Long = &H0
    Public Const fgs_PROGRAMS As Long = &H2
    Public Const fgs_STARTMENU As Long = &HB
    Public Const fgs_DESKTOPDIRECTORY As Long = &H10

    Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
    "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
    Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" (ByVal
    hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)


    Public Function folderGetSpecial(lngCSIDL As Long) As String
    Dim path As String
    Dim pidl As Long
    If SHGetSpecialFolderLocation(frmMain.hwnd, lngCSIDL, pidl) = 0 Then
    path = Space$(512)
    Call SHGetPathFromIDList(ByVal pidl, ByVal path)
    folderGetSpecial = Left$(path, InStr(path, Chr$(0)) - 1)
    Call CoTaskMemFree(pidl)
    Exit Function
    End If
    folderGetSpecial = ""
    End Function







  2. #2
    Larry Rebich Guest

    Re: Getting the Program Files path

    James:

    Your question is not clear. What exactly are you trying to retrieve?

    If you are trying to get the path of the executing program then you could
    use App.Path. If something else then a bit more info would be useful.

    Cheers,
    Larry Rebich


    "James Brown" <james@infocomp.co.uk> wrote in message
    news:3c83718f$1@10.1.10.29...
    > Hi,
    >
    > I'm using the SHGetSpecialFolderLocation API call to get the location of

    the
    > user's Program Files path. I'm calling CSIDL 38. This works fine on
    > Win2000 but it doesn't appear to work on any of the Win98 machines in the
    > office - they all return nothing. Is there a way that will work on both
    > O/Ss? I've included my module code below the signature, in case I'm doing
    > something wrong.
    >
    > --
    > Regards,
    >
    > Jamie Brown, Software Developer
    > InfoComp Ltd
    > E-Mail: james@infocomp.co.uk
    > URL: http://www.infocomp.co.uk
    >
    > ************* BEGIN CODE **************
    >
    > Option Explicit
    > Public Const fgs_FAVORITES As Long = &H6
    > Public Const fgs_DESKTOP As Long = &H0
    > Public Const fgs_PROGRAMS As Long = &H2
    > Public Const fgs_STARTMENU As Long = &HB
    > Public Const fgs_DESKTOPDIRECTORY As Long = &H10
    >
    > Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
    > "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As

    Long
    > Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll"

    (ByVal
    > hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    > Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    >
    >
    > Public Function folderGetSpecial(lngCSIDL As Long) As String
    > Dim path As String
    > Dim pidl As Long
    > If SHGetSpecialFolderLocation(frmMain.hwnd, lngCSIDL, pidl) = 0 Then
    > path = Space$(512)
    > Call SHGetPathFromIDList(ByVal pidl, ByVal path)
    > folderGetSpecial = Left$(path, InStr(path, Chr$(0)) - 1)
    > Call CoTaskMemFree(pidl)
    > Exit Function
    > End If
    > folderGetSpecial = ""
    > End Function
    >
    >
    >
    >
    >
    >




  3. #3
    Karl E. Peterson Guest

    Re: Getting the Program Files path

    Hi James --

    > I'm using the SHGetSpecialFolderLocation API call to get the location of the
    > user's Program Files path. I'm calling CSIDL 38. This works fine on
    > Win2000 but it doesn't appear to work on any of the Win98 machines in the
    > office - they all return nothing. Is there a way that will work on both
    > O/Ss?


    CSIDL_PROGRAM_FILES
    Version 5.0. Program Files folder. A typical path is C:\Program Files.
    CSIDL_PROGRAM_FILES_COMMON
    Version 5.0. A folder for components that are shared across applications. A typical
    path is C:\Program Files\Common. Valid only for Windows NT® and Windows® 2000
    systems.

    Looks like that one requires v5 of Shell32...

    http://msdn.microsoft.com/library/en...ersguide/versi
    ons.asp

    Is IE5+ installed on those 98 boxes?

    Later... Karl
    --
    [Microsoft Basic: 1976-2001, RIP]


  4. #4
    Alan Gillott Guest

    Re: Getting the Program Files path

    Not all the special folders are supported on Win 98. Anything that is
    slightly NT oriented doesn't work. You'll just have intercept the missing
    csidl and substitute an appropriate alternative: in this case 2
    I don't even bother with 38. I haven't played to see what it returns.
    You might, just might, get away with adding the appropriate Registry key.
    Again, I do know that 98 doesn't bother keeping all these keys up to date,
    especially as support for alternative Program files isn't included in 98.

    "James Brown" <james@infocomp.co.uk> wrote in message
    news:3c83718f$1@10.1.10.29...
    > Hi,
    >
    > I'm using the SHGetSpecialFolderLocation API call to get the location of

    the
    > user's Program Files path. I'm calling CSIDL 38. This works fine on
    > Win2000 but it doesn't appear to work on any of the Win98 machines in the
    > office - they all return nothing. Is there a way that will work on both
    > O/Ss? I've included my module code below the signature, in case I'm doing
    > something wrong.
    >
    > --
    > Regards,
    >
    > Jamie Brown, Software Developer
    > InfoComp Ltd
    > E-Mail: james@infocomp.co.uk
    > URL: http://www.infocomp.co.uk
    >
    > ************* BEGIN CODE **************
    >
    > Option Explicit
    > Public Const fgs_FAVORITES As Long = &H6
    > Public Const fgs_DESKTOP As Long = &H0
    > Public Const fgs_PROGRAMS As Long = &H2
    > Public Const fgs_STARTMENU As Long = &HB
    > Public Const fgs_DESKTOPDIRECTORY As Long = &H10
    >
    > Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
    > "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As

    Long
    > Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll"

    (ByVal
    > hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    > Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    >
    >
    > Public Function folderGetSpecial(lngCSIDL As Long) As String
    > Dim path As String
    > Dim pidl As Long
    > If SHGetSpecialFolderLocation(frmMain.hwnd, lngCSIDL, pidl) = 0 Then
    > path = Space$(512)
    > Call SHGetPathFromIDList(ByVal pidl, ByVal path)
    > folderGetSpecial = Left$(path, InStr(path, Chr$(0)) - 1)
    > Call CoTaskMemFree(pidl)
    > Exit Function
    > End If
    > folderGetSpecial = ""
    > End Function
    >
    >
    >
    >
    >
    >




  5. #5
    James Brown Guest

    Re: Getting the Program Files path

    Hi,

    Thanks to you all for helping! I did a bit more investigation after posting
    the message and found a better alternative to SHGetSpecialFolderLocation.
    If you use the SHGetFolderPath API you can get the Program Files path for
    both Win98 and Win2000.

    --
    Regards,

    Jamie Brown, Software Developer
    InfoComp Ltd
    E-Mail: james@infocomp.co.uk
    URL: http://www.infocomp.co.uk
    "James Brown" <james@infocomp.co.uk> wrote in message
    news:3c83718f$1@10.1.10.29...
    > Hi,
    >
    > I'm using the SHGetSpecialFolderLocation API call to get the location of

    the
    > user's Program Files path. I'm calling CSIDL 38. This works fine on
    > Win2000 but it doesn't appear to work on any of the Win98 machines in the
    > office - they all return nothing. Is there a way that will work on both
    > O/Ss? I've included my module code below the signature, in case I'm doing
    > something wrong.
    >
    > --
    > Regards,
    >
    > Jamie Brown, Software Developer
    > InfoComp Ltd
    > E-Mail: james@infocomp.co.uk
    > URL: http://www.infocomp.co.uk
    >
    > ************* BEGIN CODE **************
    >
    > Option Explicit
    > Public Const fgs_FAVORITES As Long = &H6
    > Public Const fgs_DESKTOP As Long = &H0
    > Public Const fgs_PROGRAMS As Long = &H2
    > Public Const fgs_STARTMENU As Long = &HB
    > Public Const fgs_DESKTOPDIRECTORY As Long = &H10
    >
    > Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias
    > "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As

    Long
    > Public Declare Function SHGetSpecialFolderLocation Lib "shell32.dll"

    (ByVal
    > hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
    > Public Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
    >
    >
    > Public Function folderGetSpecial(lngCSIDL As Long) As String
    > Dim path As String
    > Dim pidl As Long
    > If SHGetSpecialFolderLocation(frmMain.hwnd, lngCSIDL, pidl) = 0 Then
    > path = Space$(512)
    > Call SHGetPathFromIDList(ByVal pidl, ByVal path)
    > folderGetSpecial = Left$(path, InStr(path, Chr$(0)) - 1)
    > Call CoTaskMemFree(pidl)
    > Exit Function
    > End If
    > folderGetSpecial = ""
    > End Function
    >
    >
    >
    >
    >
    >




  6. #6
    Join Date
    Dec 2007
    Posts
    1

    Unhappy

    Quote Originally Posted by James Brown
    Hi,

    Thanks to you all for helping! I did a bit more investigation after posting
    the message and found a better alternative to SHGetSpecialFolderLocation.
    If you use the SHGetFolderPath API you can get the Program Files path for
    both Win98 and Win2000.
    Hi Jamie,

    I have also tried SHGetFolderPath on windows 98. That is giving me Error that
    "The TEST.EXE file is linked to missing Export SHELL32.DLL SHGetFolderPath"

  7. #7
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    Quote Originally Posted by somnathmali
    I have also tried SHGetFolderPath on windows 98. That is giving me Error that
    "The TEST.EXE file is linked to missing Export SHELL32.DLL SHGetFolderPath"
    Welcome to DevX

    Post the code that you used. What folder are you trying to get the path to?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center