调用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);
[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);
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货