Results 1 to 4 of 4

Thread: reading the loginname

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    5

    reading the loginname

    Hi,
    I want to know that is this possible to read the user which has logged in on a windows machine from a VB6.0 application.For ex.there is a user named jeff who logs in ,I want my application to create a read only text file named jeff.txt mentioning the time when he logged in and logged out.The data should be appended to this file everytime jeff logs in and logs out.

    manish

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: reading the loginname

    i know there is an api call to check the name of the person currently logged in. check allapi.net to get the username. once u have done that, what you can do is make the program invisible, put it up in startup items for all users, and in the form_unload you can add the logout time and save the login time and logout time.

  3. #3
    KING BODWAD XXI BodwadUK's Avatar
    Join Date
    Aug 2002
    Location
    Nottingham
    Posts
    2,176

    Re: reading the loginname

    VB Code:
    1. Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    From API GUIDE

    VB Code:
    1. 'This project needs a timer
    2. Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    3. Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
    4. Private Declare Function IsIconic Lib "user32" (ByVal hwnd As Long) As Long
    5. Private Sub Form_Load()
    6.     'KPD-Team 1998
    7.     'URL: [url]http://www.allapi.net/[/url]
    8.     'E-Mail: [email][email protected][/email]
    9.     Timer1.Interval = 100
    10.     Timer1.Enabled = True
    11.     Dim strTemp As String, strUserName As String
    12.     'Create a buffer
    13.     strTemp = String(100, Chr$(0))
    14.     'Get the temporary path
    15.     GetTempPath 100, strTemp
    16.     'strip the rest of the buffer
    17.     strTemp = Left$(strTemp, InStr(strTemp, Chr$(0)) - 1)
    18.  
    19.     'Create a buffer
    20.     strUserName = String(100, Chr$(0))
    21.     'Get the username
    22.     GetUserName strUserName, 100
    23.     'strip the rest of the buffer
    24.     strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    25.  
    26.     'Show the temppath and the username
    27.     MsgBox "Hello " + strUserName + Chr$(13) + "The temp. path is " + strTemp
    28. End Sub
    29. Private Sub Timer1_Timer()
    30.     Dim Boo As Boolean
    31.     'Check if this form is minimized
    32.     Boo = IsIconic(Me.hwnd)
    33.     'Update the form's caption
    34.     Me.Caption = "Form minimized: " + Str$(Boo)
    35. End Sub

    HTH
    If you dribble then you are as mad as me

    Lost World Creations Website (XBOX Indie games)
    Lene Marlin

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: reading the loginname

    Once you have the username
    VB Code:
    1. Open "c:\loginfile.txt" For Append As #1
    2. Print #1, username & " logged in at: " & Now
    3. Close #1
    Bare in mind that the GetUserName API acts differently if you are running Win2000 or XP.

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