Userid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a way I can determine the windows USERID of the current user. I
would like to make some functionality available to some, but not all users?

Thanks..
 
UName = Environ("Username")

demo'd from the immediate window:

? environ("username")
ogilvytw
 
Thanks. This is getting closer, but it is not the login ID.

In my case, my Windows login ID is "wapnits", byt your technique returns
"Marvin". Further, I have the ability to change the environment, but cannot
change the userid. Thus, userid is more secure in preventing my user from
doing things he shouldn't do.
 
this give me the same, but maybe you will get different:

Private Declare Function apiGetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, nsize As Long) As Long

Sub GetUserNameTest()
MsgBox fOSUserName
End Sub

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function
 
Perfect. Thanks. What was the source of your information, and how can I
acquire it?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top