DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2005
    Posts
    1

    User last login information

    Hello,

    I need to get the last login information of an user to show it in my VC++ application.
    Do you know where can I get that information?
    Thanks.

  2. #2
    Join Date
    Oct 2004
    Location
    Baltimore MD
    Posts
    69
    I'm sure there is an easier way of doing this but, when I had to do that for work I used a VB script and sent the output to a file (i.e. “UserLoginTimes.log”). Then inside C++ I parsed the file to find the user I wanted the info from.

    Here is the script I used…

    Code:
    ' List last logon times
    ' 2005 Zak AInsworth
    On Error Resume Next
    sEnterDCs = "NSOLAB"
    sObjects = Split(sEnterDCs, ",")
    Set oDomain = GetObject("WinNT://" & sObjects(0))
    oDomain.Filter = Array("User")
    WScript.Echo "Showing last login times of accounts from: " & oDomain.Name & vbNewLine
     For Each oDomainItem In oDomain
      sUsrLogin = oDomainItem.LastLogin
      If UBound(sObjects) >= 1 Then
        For ii = 1 To UBound(sObjects)
          Set oUsr = GetObject("WinNT://" & sObjects(ii) & "/" & oDomainItem.Name & ",user")
          If oUsr.LastLogin > sUsrLogin Then sUsrLogin = oUsr.LastLogin
        Next
      End If
      WScript.Echo "Username: " & Left(oDomainItem.Name & Space(22),22) & "Last login: " & FormatDateTime(sUsrLogin)
    Next
    (on the line ‘sEnterDCs = "NSOLAB"’, change “NSOLAB” to your domain name.)

    Name the script something like “GetUserLoginTimes.vbs”.

    You can add this line of code to your C++ source…

    Code:
    System(“cscript GetUserLoginTimes.vbs > UserLoginTimes.log”);
    This will run the script and send the output to “UserLoginTimes.log”.

    Now it’s up to you to do the parsing. The script lists each user on a new line which makes is pretty easy.

    Good Luck…

    -Zak
    Last edited by Zak; 03-15-2005 at 09:41 AM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links