Results 1 to 5 of 5

Thread: get the desktop path

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    42
    hi.

    how can i get the desktop path on the client computers.

    ( even on nt or windows with more than one user.)

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Lightbulb

    To get the Desktop folder path, use this:

    Code:
    Private Const CSIDL_DESKTOP = &H0
    Private Const MAX_PATH = 255
    Private Declare Function SHGetSpecialFolderLocation Lib "Shell32" (ByVal hwndOwner As Long, ByVal nFolder As Integer, ppidl As Long) As Long
    Private Declare Function SHGetPathFromIDList Lib "Shell32" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal szPath As String) As Long
    
    Public Function GetDesktopFolderPath(ByVal pHwnd As Long) As String
        Dim lReturn As Long
        Dim lPidl   As Long
        Dim lPath   As Long
        Dim sPath   As String
    
        sPath = Space$(MAX_PATH)
        lReturn = SHGetSpecialFolderLocation(pHwnd, CSIDL_DESKTOP, lPidl)  ' Get lPidl for Id...
        If lReturn = 0 Then                                    ' If success is 0
            lReturn = SHGetPathFromIDList(lPidl, sPath)        '   Get Path from Item Id List
            If lReturn = 1 Then                                '   If success is 1
                sPath = Left(sPath, InStr(sPath, vbNullChar) - 1)             '     Fix path string
                GetDesktopFolderPath = sPath                    '     Return Favorite path
            End If
        End If
    End Function
    Then you can call this function to get the path of the desktop folder:


    Dim strPath As String

    strPath = GetDesktopFolderPath(Me.Hwnd)


    strPath now holds the path to the Desktop.

  3. #3
    Guest
    Or you could just check if one exists.

    Public Function DirExists(ByVal strDirName As String) As Integer

    Dim strDummy As String

    On Error Resume Next

    If Right$(strDirName, 1) <> "\" Then
    strDirName = strDirName & "\"
    End If

    strDummy = Dir$(strDirName & "*.*", vbDirectory)
    DirExists = Not (strDummy = vbNullString)

    Err = 0
    End Function

    If DirExists("C:\Windows\Desktop\") Then
    Msgbox "Desktop Folder exists"
    Else
    Msgbox "Desktop Folder doesn't exists! Where the hell could it be?"
    End If

  4. #4
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Using Dir function you have to be absolutely sure that windows directory is installed under C:\Windows.
    Where using APIs you don'thave to care where it is installed under.

  5. #5
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    Very true.

    Winnt has the desktop in the profiles\username dir and win2k has bits of it in different places.

    Definately use the API
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

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