Solved

Network login name

Posted on 2000-03-14
6
129 Views
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?)

Cheers
0
Comment
Question by:aluiken
  • 3
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 200 total points
Comment Utility
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


Cheers!®©
0
 
LVL 3

Expert Comment

by:jetforce
Comment Utility
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

Jetforce
0
 
LVL 3

Expert Comment

by:jetforce
Comment Utility
I was too late, just ignore my post
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 14

Expert Comment

by:mcrider
Comment Utility
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



Cheers!®©
0
 
LVL 1

Author Comment

by:aluiken
Comment Utility
Very good, thx
0
 
LVL 14

Expert Comment

by:mcrider
Comment Utility
Thanks for the points! Glad I could help!


Cheers!®©
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now