PDA

Click to See Complete Forum and Search --> : Username


death
Nov 25th, 1999, 06:03 AM
What set of commands would i use to tell me what user is logged on

Keiko
Nov 25th, 1999, 07:24 AM
Hi Death,

You can use this set of commands.

----------------------

Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal rsBuffer As String, rlSize As Long) As Long

Option Explicit

Private Sub Form_Load()
Dim dsBuffer As String
Dim dlSize As Long

dsBuffer = Space$(255)
dlSize = Len(dsBuffer)
Call GetUserName(dsBuffer, dlSize)

If (dlSize > 0) Then
Me.txtUserID.Text = Left$(dsBuffer, dlSize)
Else
Me.txtUserID.Text = vbNullString
End If

End Sub


-------------

Does it help ?

Regards

Compwiz
Nov 25th, 1999, 08:47 AM
Or, the exact same thing in fewer lines of code:


Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal rsBuffer As String, rlSize As Long) As Long
Private Sub Form_Load()
Dim dsBuffer As String, dlSize As Long
dsBuffer = Space$(255)
dlSize = Len(dsBuffer)
Call GetUserName(dsBuffer, dlSize)
If (dlSize > 0) Then txtUserID.Text = Left$(dsBuffer, dlSize) Else txtUserID.Text = "UNKNOWN USER"
End Sub


Yes, I'm bored.

------------------
Tom Young, 14 Year Old
tyoung@stny.rr.com
ICQ: 15743470 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer

Compwiz
Nov 25th, 1999, 08:48 AM
Oh, BTW Keiko, You don't have to put a Me. in front of a control's name. Nothing important though.

Keiko
Nov 25th, 1999, 09:36 AM
Compwiz,

I believe the purpose of this forum is to help each other.

I can write a very compact code, but it may be difficult for others to read. As long as the concept is there, the questioners can re-structure the code in their ways.

Also, I know "Me" kind of thing. This morning I just made a fast Cut and Paste from my original code.

Any more comment kid ?


[This message has been edited by Keiko (edited 11-25-1999).]