Re: How to get current user?
Hi,
Item 39 in this thread http://www.vbforums.com/showthread.php?t=342035
Tells you how to get the current user
Al
Re: How to get current user?
environ("userprofile") will return the path to the current user's folder system
getspecialfolder API call can get the actual desktop folder
Re: How to get current user?
Code:
Option Explicit
Private Declare Function SHGetSpecialFolderPath Lib "shell32.dll" Alias _
"SHGetSpecialFolderPathA" _
(ByVal hwnd As Long, _
ByVal pszPath As String, _
ByVal csidl As Long, _
ByVal fCreate As Long) As Long
Private Const CSIDL_DESKTOP = &H0
Private Const MAX_PATH = 260
Private Function GetDesktopFolderPath() As String
Dim sDesktopPath As String
sDesktopPath = Space$(MAX_PATH)
SHGetSpecialFolderPath Me.hwnd, sDesktopPath, CSIDL_DESKTOP, False
GetDesktopFolderPath = Left$(sDesktopPath, InStr(sDesktopPath, vbNullChar) - 1)
End Function
Private Sub Command1_Click()
Dim strDesktop As String
strDesktop = GetDesktopFolderPath
MsgBox strDesktop
End Sub
Re: How to get current user?
To find the location of special folders (like the Desktop etc), do not even think about the username - as it doesn't actually need to be related to the names of the folders (there is also the issue that the parent folders can be called something else, and/or be on a different drive).
Instead you should use the API's designed for finding paths, a good example of which can be seen here.
edit: it seems I was slow, and was last in the rush. :(
Re: How to get current user?
Re: How to get current user?
wow lots of replies. thanks. i will try them. I will post if its resolved. thanks.