Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get NT username in VB application ?

Status
Not open for further replies.

snr

Programmer
Oct 8, 2001
78
0
0
US
Depending on the NT login I want to show the options in the VB form. How can I get the windows username. We are using Windows 2000 ?

thanks
 
'Declarations - Public or Private
' Form Level, Module Level
Public Declare Function GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long

Public Function GetWindowsLoginUserID() As String
Dim rtn As Long
Dim sBuffer As String
Dim lSize As Long
Dim lngInstr As Long
sBuffer = String$(260, Chr$(0))
lSize = Len(sBuffer)
rtn = GetUserName(sBuffer, lSize)
If rtn <> 0 Then
sBuffer = Left$(sBuffer, lSize)
lngInstr = InStr(sBuffer, Chr$(0))
If lngInstr > 0 Then
sBuffer = _
Left$(sBuffer, lngInstr - 1)
End If
GetWindowsLoginUserID = sBuffer
Else
GetWindowsLoginUserID = &quot;&quot;
End If
End Function Compare Code (Text)
Generate Sort in VB or VBScript
 
[tt]MsgBox Environ$(&quot;USERNAME&quot;)[/tt]

VCA.gif
 
Thanks a lot Alt255 !
It worked !!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top