Results 1 to 6 of 6

Thread: [Resolved] Program Files path

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    [Resolved] Program Files path

    Hi, i'm trying to make a label's caption say the computers program files dir but the code i'm using just makes the caption say the desktop dir...?

    Heres the code
    VB Code:
    1. Private Enum CSIDL_VALUES
    2.     CSIDL_PROGRAM_FILES = &H26
    3. End Enum
    4. Private Const SHGFP_TYPE_CURRENT = &H0
    5. Private Const SHGFP_TYPE_DEFAULT = &H1
    6. Private Const MAX_LENGTH = 260
    7. Private Const S_OK = 0
    8. Private Const S_FALSE = 1
    9. Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    10. Private Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long
    11. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    12. Private Const LB_SETTABSTOPS As Long = &H192
    13.  
    14. Private Sub Form_Load()
    15. Dim csidl As Long
    16. Label1.Caption = GetFolderPath(csidl, CSIDL_PROGRAM_FILES)
    17. End Sub
    18.  
    19. Private Function GetFolderPath(csidl As Long, SHGFP_TYPE As Long) As String
    20. Dim buff As String
    21. Dim dwFlags As Long
    22. buff = Space$(MAX_LENGTH)
    23. If SHGetFolderPath(Me.hwnd, csidl Or dwFlags, -1, SHGFP_TYPE, buff) = S_OK Then
    24. GetFolderPath = TrimNull(buff)
    25. End If
    26. End Function
    27. Private Function TrimNull(startstr As String) As String
    28. TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
    29. End Function

    Thanks in advance
    Last edited by BefunMunkToloGen; Mar 31st, 2005 at 02:19 AM.

  2. #2
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Program Files path

    Have a look at this thread: http://www.vbforums.com/showthread.php?t=219859
    It talks about finding the 'My Documents' folder, but I think it is also applicable to 'Program Files'.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Program Files path

    I just had a play with the code you posted and this appears to work:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const CSIDL_PROGRAM_FILES As Long = &H26
    4. Private Const MAX_LENGTH = 260
    5. Private Const S_OK = 0
    6. Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    7. Private Declare Function SHGetFolderPath Lib "shfolder.dll" Alias "SHGetFolderPathA" (ByVal hwndOwner As Long, ByVal nFolder As Long, ByVal hToken As Long, ByVal dwReserved As Long, ByVal lpszPath As String) As Long
    8.  
    9. Private Sub Form_Load()
    10.     Dim csidl As Long
    11.     Label1.Caption = GetFolderPath(CSIDL_PROGRAM_FILES)
    12. End Sub
    13.  
    14. Private Function GetFolderPath(SHGFP_TYPE As Long) As String
    15.    
    16.     Dim buff As String
    17.     buff = Space$(MAX_LENGTH)
    18.     If SHGetFolderPath(Me.hwnd, SHGFP_TYPE, -1, SHGFP_TYPE, buff) = S_OK Then
    19.         GetFolderPath = TrimNull(buff)
    20.     End If
    21.  
    22. End Function
    23.  
    24. Private Function TrimNull(startstr As String) As String
    25.     TrimNull = Left$(startstr, lstrlenW(StrPtr(startstr)))
    26. End Function
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Program Files path

    Thanks but that doesn't really help. I can get it work with lists just not message boxes or labels?

    Edit: Lol you must have posted that like 2 seconds ago , ill check it out thanks

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Program Files path

    Beautiful! Thanks mate! Will help my programme alot

  6. #6
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: [Resolved] Program Files path

    No sweat. Glad to help.
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width