[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


Network login name

Posted on 2000-03-14
Medium Priority
Last Modified: 2010-05-02
Hi there,

Is there a way to find out the currently logged in user name for microsoft networking (so NOT the windows password?)

Question by:aluiken
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 14

Accepted Solution

mcrider earned 800 total points
ID: 2616255
Here's an example:

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

Private Sub Command1_Click()
    Dim lName As String
    Dim lLen As Long
    Dim RetVal As Long
    Dim CurUser As String
    lLen = 199
    lName = String$(200, 0)
    RetVal = GetUserName(lName, lLen)
    If RetVal <> 0 Then CurUser = Left$(lName, lLen - 1) Else CurUser = ""
    MsgBox CurUser
End Sub


Expert Comment

ID: 2616256
If I understand right, you just want to get the username of who is logged in? if so try this API
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

and then just call it eg:-
GetUserName strUser, 10

lpbuffer is the string that you want the username to go into and nSize is the length of the string.

hope this helps


Expert Comment

ID: 2616259
I was too late, just ignore my post
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 14

Expert Comment

ID: 2616276
By the way, here's another way:

Private Declare Function WNetGetUserA Lib "mpr" (ByVal lpName As String, ByVal lpUserName As String, lpnLength As Long) As Long
Function GetUserID() As String
    Dim lName As String * 255
    lName = Space(255)
    Call WNetGetUserA(vbNullString, lName, 255&)
    GetUserID = Left$(lName, InStr(lName, vbNullChar) - 1)
End Function

Private Sub Command1_Click()
    MsgBox GetUserID
End Sub


Author Comment

ID: 2616294
Very good, thx
LVL 14

Expert Comment

ID: 2616314
Thanks for the points! Glad I could help!


Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question