PDA

Click to See Complete Forum and Search --> : Get the desktop directory?


hall
Aug 17th, 2000, 09:25 AM
Is there any way to get the desktop directory within VB code similar to how the windows directory or system directories are obtainable using GetSystemDirectory and GetSystemDirectory, respectively?

Thanks.

gwdash
Aug 17th, 2000, 10:28 AM
Try this:

Const CSIDL_DESKTOPDIRECTORY = &H10

Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias "SHGetSpecialFolderPathA" (ByVal hwndOwner As Long, ByVal lpszPath As String, ByVal nFolder As Long, ByVal fCreate As Long) As Long

Function GetDesktopFolder()


Dim pathname As String ' receives the path of Desktop
Dim retval As Long ' return value

' Make enough room in the buffer to receive the string.
pathname = Space(260)
' Get the path name of the My Documents special folder
retval = SHGetSpecialFolderPath(Form1.hWnd, pathname, CSIDL_DESKTOPDIRECTORY, 0)
' Remove the empty space from the string.
pathname = Left(pathname, InStr(pathname, vbNullChar) - 1)
' Display the result.
GetDesktopFolder = pathname

End Function