A próbowałeś z:
System.Security.Principal
i System.DirectoryServices.AccountManagement
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.DirectoryServices.AccountManagement;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
textBox2.Text = WindowsIdentity.GetCurrent().Name.Split('\\')[0];
string userName = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
string machineName = WindowsIdentity.GetCurrent().Name.Split('\\')[0];
PrincipalContext c = new PrincipalContext(ContextType.Machine, machineName);
//Specific User
//UserPrincipal uc = UserPrincipal.FindByIdentity(c, "user");
//DateTime? LoggedInTime = uc.LastLogon;
//Current LoggedIn User
UserPrincipal uc = UserPrincipal.FindByIdentity(c, userName);
DateTime? CurrentUserLoggedInTime = uc.LastLogon;
textBox3.Text = "Last logon (Date Time):" + CurrentUserLoggedInTime.ToString();
}
}
}