Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Login Time

Login Time

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yoyosh 0
    wrote on last edited by
    #1

    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.

    P 1 Reply Last reply
    0
    • Y Yoyosh 0

      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.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      Y 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        Y Offline
        Y Offline
        Yoyosh 0
        wrote on last edited by
        #3

        Thanks for effort but don`t you have some C# code?

        P 1 Reply Last reply
        0
        • Y Yoyosh 0

          Thanks for effort but don`t you have some C# code?

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          -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
          
          E 1 Reply Last reply
          0
          • P Pete OHanlon

            -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
            
            E Offline
            E Offline
            ednrgc
            wrote on last edited by
            #5

            Can you do my homework too? :laugh::laugh::laugh:

            P 1 Reply Last reply
            0
            • E ednrgc

              Can you do my homework too? :laugh::laugh::laugh:

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups