VB Code:
  1. Option Explicit
  2.  
  3. Const CSIDL_COOKIES As Long = &H21
  4.  
  5. Private Const ERROR_SUCCESS = 0&
  6.  
  7. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" _
  8.                         (ByVal pidl As Long, ByVal pszPath As String) As Long
  9. Private Declare Function SHGetSpecialFolderLocation Lib "shell32.dll" _
  10.                         (ByVal hwndOwner As Long, ByVal nFolder As Long, pidl As Long) As Long
  11. Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
  12.  
  13. Public Function GetSpecialFolder(hwnd As Long, CSIDL As Long) As String
  14. Dim pidl As Long
  15. Dim Pos As Long
  16. Dim sPath As String
  17.      
  18.     If SHGetSpecialFolderLocation(hwnd, CSIDL, pidl) = ERROR_SUCCESS Then
  19.         sPath = Space$(260)
  20.         If SHGetPathFromIDList(ByVal pidl, ByVal sPath) Then
  21.             Pos = InStr(sPath, Chr$(0))
  22.             If Pos Then
  23.                 GetSpecialFolder = Left$(sPath, Pos - 1)
  24.             End If
  25.             Call CoTaskMemFree(pidl)
  26.         End If
  27.     End If
  28.    
  29. End Function
  30.  
  31. Private Sub Form_Load()
  32. Dim strStartUpFolder As String
  33.  
  34.     strStartUpFolder = GetSpecialFolder(Me.hwnd, CSIDL_COOKIES)
  35.     MsgBox strStartUpFolder
  36.  
  37. End Sub