我正在尝试使用 c# 识别我的网络中的工作站,使用 c# 检索它的可能方法是什么。
我正在使用以下代码:
[DllImport("Netapi32.dll")]
static extern unsafe int NetWkstaGetInfo(IntPtr servername, int level, byte** bufptr);
[DllImport("Netapi32.dll")]
static extern unsafe int NetApiBufferFree(byte* bufptr);
[STAThread]
static unsafe void Main(string[] args)
{
byte* bp = null;
int rc = NetWkstaGetInfo(IntPtr.Zero, 102, &bp);
WkstaInfo102* wip = (WkstaInfo102*)bp;
Console.WriteLine("System {0} has {1} users logged on", Marshal.PtrToStringAuto(wip->computername), wip->logged_on_users);
rc = NetApiBufferFree(bp);
}
}