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);
}
}