I have a VB6 app that uses the Environ("userprofile") command to determine the location of the My Documents folder for the currently logged in user.

This has been working fine for ages with no problems. One particular client has had the user directory redirected to a network location so that he can back up all the user data. The problem I face is the Environ("userprofile") still returns the local C Drive location for the user and not the mapped network location.

How can I determine where the real user profile has been mapped to ? Is it a registry entry that can be read ?

Hi,

Declare this API at the top :

Private Declare Function SHGetFolderPath Lib "shfolder.dll" _
   Alias "SHGetFolderPathA" _
  (ByVal hwndOwner As Long, _
   ByVal nFolder As Long, _
   ByVal hToken As Long, _
   ByVal dwReserved As Long, _
   ByVal lpszPath As String) As Long

to Get the path :

Dim MyPath As String
    MyPath = Space(260)
    Call SHGetFolderPath(Me.hWnd, 0, -1, &HC, MyPath)
    MsgBox MyPath

Regards
Veena

commented: Very Well Done. +8

QVeen72 thanks for the update but is SHGetFolderPath part of the Win32 API. I can't find any record of that call.

QVeen72 I have got it working, many thanks for your help I am waiting to see if it reads the clients profile on their system. Thank you once again.

I've been trying to get the local dynamic user path to work but it doesn't seem to be.

John, what is your original code? Here is what I have but it isn't finding the file. I am using a checkbox and that feature is working but when I have it checked to use the path, it cannot find the file in that path (i.e. default.rdp). I have even tried strPath = Environ("%userprofile%\MyDocu~1") and strPath = Environ("%userprofile%\My Documents")

===> Code <===

strPath = Environ("%userprofile%" & "My Documents")
        If RDPConsole.Checked = True Then
            strRemoteConnect = ("mstsc /edit " & strPath & "default.rdp /v:") & IPBox1.Text

        Else
            strRemoteConnect = ("mstsc /v:") & IPBox1.Text
        End If
        Shell(strRemoteConnect, vbNormalNoFocus)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.