Results 1 to 4 of 4

Thread: How read own username?

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Croatia
    Posts
    52
    I know my user name but how read it in source (if you know answer, please write (source) in VB). My OS is Windows 2000.

    TNKS!

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633
    Code:
    Option Explicit
    Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Sub Main()
      Dim str_Data As String * 25
      Call GetUserName(str_Data, Len(str_Data))
      MsgBox Left(str_Data, InStr(str_Data, Chr(0)) - 1)
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  3. #3

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Croatia
    Posts
    52

    Thank You!

    WORK!
    Thank You!


  4. #4
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Here's a real simple app I wrote to see who was using my computer at work:
    Code:
    'Form1 visible property is false
    Private Declare Function GetUserName Lib "advapi32.dll" Alias _
                   "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) _
                   As Long
    Private Sub Form_Load()
    Dim s As String
    Dim cnt As Long
    Dim dl As Long
    Dim CurUser As String
    cnt = 199
    s = String$(200, 0)
    dl = GetUserName(s, cnt)
    If dl <> 0 Then CurUser = Left$(s, cnt) Else CurUser = ""
    
    Open "c:\windows\whoson.log" For Append As #1
    Print #1, CStr(Now) & ", User: " & CurUser
    Close #1
    Unload Form1
    Set Form1 = Nothing
    End Sub
    I put it in the run key in the registry and it runs when you first boot/login. It logs the date
    and time and the users login name.

    Editting: Forgot the Set statement

    [Edited by dsy5 on 11-11-2000 at 01:24 PM]
    Donald Sy - VB (ab)user

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width