调用API GetUserName可以。[DllImport("Advapi32", SetLastError=true, CharSet=CharSet.Auto)]
[return:MarshalAs(UnmanagedType.Bool)]
public static extern bool GetUserName(
StringBuilder lpNameBuffer,
[MarshalAs(UnmanagedType.U4)]
ref int nSize);或者使用ADSI:
DirectoryEntry userEntry = new DirectoryEntry("WinNT://scenic/aspnet,User");
Console.WriteLine(userEntry.Properties["fullname"].Value);