CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2012
    Posts
    13

    get current user location error

    Hi ,

    I write to get the current user name , and the result is :

    A> In line 15 , the result is "Raymond\Favorites" , where Raymond is the current user name which locate at Drive D:\

    My question is : how can I get "D:\Raymond\Favorites" ???

    B> In line 16 , the result is "Raymond\Documents" in Win7

    My question is : why is it not "Raymond\Favorites"

    I've try to use : FileName = sUserName & "\Videos" , but with the same result : "Raymond\Documents" ???


    1. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" _
    2. (ByVal lpBuffer As String, nSize As Long) As Long

    3. Private Sub Form_Load()
    4. Dim sUserName As String
    5. Dim lSize As Long

    6. lSize = 20
    7. sUserName = Space(20)
    8. Call GetUserName(sUserName, lSize)
    9. sUserName = Trim(sUserName)
    10. sUserName = Left(sUserName, Len(sUserName) - 1)
    11. '------------------------------------------------------------------------------
    12. Dim Res
    13. Dim FileName
    14. FileName = sUserName & "\Favorites"
    15. MsgBox FileName
    16. Res = Shell("explorer.exe " & FileName, vbNormalFocus)

    17. End Sub

    Thanks for everybody.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: get current user location error

    Have you checked to see what GetUserName is returning?
    Always use [code][/code] tags when posting code.

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

Featured