How to get system login time using VB
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to get system login time using VB

  1. #1
    Join Date
    Mar 2002
    Location
    India
    Posts
    1

    How to get system login time using VB

    i want to create a VB application that will record the system time each time a new user logins to the system.


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to get system login time using VB

    This is a starting point:
    add a bas module in a project, and remove any form
    make the startup object the "Sub Main"
    Compile it, and put a shortcut in Startup menu of "all user"
    (you may write path and name of shortcut in registry instead, if you know where
    to find the "Run" key for all users)
    This will write in a file (="c:\temp\LoginTime.txt" username and time of login
    each time someone re-login.
    This runs on "client side" (ie: if you have 10 pc, you will have to put this
    program in all of them, and you will get 10 files, one for each pc)

    option Explicit

    private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (byval lpBuffer as string, nSize as Long) as Long
    Sub Main()
    Dim strUserName as string
    'Create a buffer
    strUserName = string(100, Chr$(0))
    'get the username
    GetUserName strUserName, 100
    'strip the rest of the buffer
    strUserName = Left$(strUserName, InStr(strUserName, Chr$(0)) - 1)
    Open "c:\temp\LoginTime.txt" for Append as #1
    print #1,
    print #1, "---"
    print #1, strUserName
    print #1, "time loggedIn: " & Now
    print #1, "---"
    Close 1#
    'we have no form
    'completed sub main program should stop
    'let us make it abruptly
    End
    End Sub





    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris, Dr_Michael
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center