Solved

Network login name

Posted on 2000-03-14
6
131 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
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


Cheers!®©
0
 
LVL 3

Expert Comment

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

Jetforce
0
 
LVL 3

Expert Comment

by:jetforce
ID: 2616259
I was too late, just ignore my post
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 14

Expert Comment

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



Cheers!®©
0
 
LVL 1

Author Comment

by:aluiken
ID: 2616294
Very good, thx
0
 
LVL 14

Expert Comment

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


Cheers!®©
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

777 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