I did a bit of searching and came across this thread I tested the code from Flyguy and it worked for me.
I then found this thread and got it printing the path to a label for testing.
Private Declare Function SHGetSpecialFolderLocation Lib "Shell32.DLL" (ByVal hWndOwner As Long, ByVal SHFolder As Long, ByRef idl As Long) As Long
Private Declare Function SHGetPathFromIDList Lib "Shell32.DLL" (ByVal idl As Long, ByVal Path As String) As Long
Public Enum SystemFolder CSIDL_MYMUSIC = &HD ' "My Music" folder End Enum
Public Function SystemPath(ByVal PathID As SystemFolder) As String Dim lIDL As Long ' directory IDL value Dim sBuff As String sBuff = Space$(1024) Dim n As Long n = SHGetSpecialFolderLocation(0, PathID, lIDL) If n Then Exit Function n = SHGetPathFromIDList(lIDL, sBuff) If n > 0 Then n = InStr(sBuff, Chr$(0)) - 1 sBuff = Left$(sBuff, n) If Right$(sBuff, 1) <> "\" Then sBuff = sBuff & "\" SystemPath = sBuff End If End Function
Private Sub Command#_Click() 'I added a label and changed it to the path for testing Label2 = SystemPath(&HD) End Sub
You can add more SystemFolders to the Enum if you were wanting to check other folders.
Alex
Sorry, only students may add comments.
Click here for more
information on how you can set up an account.
If you are a Visitor, go ahead and post your reply as a
new comment, and we'll move it here for you
once it's approved. Be sure to use the same name and email address.
This thread is now CLOSED. If you wish to comment, start a NEW discussion in
Visual Basic Forum.