I am trying to find a way to get the My Documents path. I have searched the forum, but haven't found anything helpful. I need to get it for all windows os from 98 to present. Anyone know how I can do that?
Thank you for your help.
Printable View
I am trying to find a way to get the My Documents path. I have searched the forum, but haven't found anything helpful. I need to get it for all windows os from 98 to present. Anyone know how I can do that?
Thank you for your help.
Here is a sample from the allapi network - use CSIDL_PERSONAL for what you need:
EDIT: sample from allapi was full of bugs so I modified it.VB Code:
Option Explicit Private Const CSIDL_PERSONAL = &H5 Private Const NOERROR = 0 Private Type SHTEMID cb As Long abID As Byte End Type Private Type ITEMIDLIST mkid As SHTEMID End Type Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _ (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As ITEMIDLIST) As Long Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _ "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long Private Sub Form_Load() Debug.Print "My Documents path: " & GetSpecialfolder(CSIDL_PERSONAL) End Sub Private Function GetSpecialfolder(CSIDL As Long) As String Dim r As Long Dim IDL As ITEMIDLIST Dim Path$ 'Get the special folder r = SHGetSpecialFolderLocation(100, CSIDL, IDL) If r = NOERROR Then 'Create a buffer Path$ = Space$(512) 'Get the path from the IDList r = SHGetPathFromIDList(ByVal IDL.mkid.cb, ByVal Path$) 'Remove the unnecessary chr$(0)'s GetSpecialfolder = Left$(Path, InStr(Path, Chr$(0)) - 1) Exit Function End If GetSpecialfolder = "" End Function
try the HOMEPATH Environment Variable:
;)VB Code:
MsgBox Environ("HOMEPATH")