Network login name

Posted on 2000-03-14
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 200 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

688 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