-
October 12th, 2012, 12:14 PM
#1
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.
-
October 13th, 2012, 09:47 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|