Login Time
-
How to get user`s login time? I don`t mean the time when the machine has been turned on, just the time when user has logged to Windows.
This article might help: http://weblogs.asp.net/ralfw/archive/2004/01/04/47442.aspx[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
This article might help: http://weblogs.asp.net/ralfw/archive/2004/01/04/47442.aspx[^]
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
-Yoyosh- wrote:
Thanks for effort but don`t you have some C# code?
Good grief man. Do you want blood?
using System; using System.Runtime.InteropServices; using System.Collections; namespace UserLastLogin { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // // TODO: Add code to start application here // UserLoginDetails details = new UserLoginDetails(); ArrayList list = details.Users; foreach (UserLastLogin.UserLoginDetails.UserLastLogon users in list) { Console.WriteLine("User {0}, last logged in on {1}\r\n", users.UserName, users.LastLogon); } Console.ReadLine(); } } public class UserLoginDetails { [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct USER_INFO { public string Name; public string Password; public int PasswordAge; public int Priv; public string HomeDirectory; public string Comment; public int Flags; public string ScriptPath; public int AuthorisationFlags; public string FullName; public string UserComment; public string Param; public string Workstations; public int LastLogon; public int LastLogoff; public int AccountExpires; public int MaximumStorage; public int UnitsPerWeek; public byte LogonHours; public int BadPasswordCount; public int NumberOfLogons; public string LogonServer; public int CountryCode; public int CodePage; } [DllImport("Netapi32.dll")] extern static int NetUserEnum([MarshalAs(UnmanagedType.LPWStr)] string servername, int level, int filter, out IntPtr bufptr, int prefmaxlen, out int entriesread, out int totalentries, out int resume_handle); [DllImport("Netapi32.dll")] extern static int NetApiBufferFree(IntPtr Buffer); public class UserLastLogon { private string _userName; private DateTime _lastLogon; internal UserLastLogon(USER_INFO info) { _userName = info.Name; _lastLogon = new DateTime(1970,1,1,0,0,0,0).AddSeconds(info.LastLogon); } public string UserName { get { return _userName ; } } public DateTime LastLogon { get { return _lastLogon ; } } } private ArrayList _users = new ArrayList(); public UserLoginDetail
-
-Yoyosh- wrote:
Thanks for effort but don`t you have some C# code?
Good grief man. Do you want blood?
using System; using System.Runtime.InteropServices; using System.Collections; namespace UserLastLogin { /// /// Summary description for Class1. /// class Class1 { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { // // TODO: Add code to start application here // UserLoginDetails details = new UserLoginDetails(); ArrayList list = details.Users; foreach (UserLastLogin.UserLoginDetails.UserLastLogon users in list) { Console.WriteLine("User {0}, last logged in on {1}\r\n", users.UserName, users.LastLogon); } Console.ReadLine(); } } public class UserLoginDetails { [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] public struct USER_INFO { public string Name; public string Password; public int PasswordAge; public int Priv; public string HomeDirectory; public string Comment; public int Flags; public string ScriptPath; public int AuthorisationFlags; public string FullName; public string UserComment; public string Param; public string Workstations; public int LastLogon; public int LastLogoff; public int AccountExpires; public int MaximumStorage; public int UnitsPerWeek; public byte LogonHours; public int BadPasswordCount; public int NumberOfLogons; public string LogonServer; public int CountryCode; public int CodePage; } [DllImport("Netapi32.dll")] extern static int NetUserEnum([MarshalAs(UnmanagedType.LPWStr)] string servername, int level, int filter, out IntPtr bufptr, int prefmaxlen, out int entriesread, out int totalentries, out int resume_handle); [DllImport("Netapi32.dll")] extern static int NetApiBufferFree(IntPtr Buffer); public class UserLastLogon { private string _userName; private DateTime _lastLogon; internal UserLastLogon(USER_INFO info) { _userName = info.Name; _lastLogon = new DateTime(1970,1,1,0,0,0,0).AddSeconds(info.LastLogon); } public string UserName { get { return _userName ; } } public DateTime LastLogon { get { return _lastLogon ; } } } private ArrayList _users = new ArrayList(); public UserLoginDetail
-
ednrgc wrote:
Can you do my homework too?
Sure - bring it on:-D:-D:-D.
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.