using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace ConsoleApplication6
{
class Class1
{
[StructLayout(LayoutKind.Sequential, Pack=4)]
struct WKSTA_INFO_100
{
public int wki100_platform_id;
public IntPtr wki100_computername;
public IntPtr wki100_langroup;
public int wki100_ver_major;
public int wki100_ver_minor;
}
[DllImport("Netapi32.dll")]
// NET_API_STATUS NetWkstaGetInfo(
// LPWSTR servername,
// DWORD level,
// LPBYTE* bufptr
// );
static extern int NetWkstaGetInfo(string servername, int level, out IntPtr bufptr);
// NET_API_STATUS NetApiBufferFree(
// LPVOID Buffer
// );
[DllImport("Netapi32.dll")]
private static extern int NetApiBufferFree(IntPtr bufptr);
[STAThread]
static void Main(string[] args)
{
Test_SystemInformation();
Test_NetWkstaGetInfo();
Console.ReadLine();
}
static void Test_SystemInformation()
{
Console.WriteLine("Environment.UserDomainName:" + Environment.UserDomainName);
Console.WriteLine("SystemInformation.UserDomainName:" + SystemInformation.UserDomainName);
Console.WriteLine("SystemInformation.ComputerName:" + SystemInformation.ComputerName);
Console.WriteLine("----------------------");
}
static void Test_NetWkstaGetInfo()
{
IntPtr bufptr;
NetWkstaGetInfo( null, 100, out bufptr);
WKSTA_INFO_100 s = (WKSTA_INFO_100)Marshal.PtrToStructure(bufptr, typeof(WKSTA_INFO_100));
string workgroup = Marshal.PtrToStringUni(s.wki100_langroup);
string compname = Marshal.PtrToStringUni(s.wki100_computername);
Console.WriteLine("Workgroup:" + workgroup);
Console.WriteLine("Compname:" + compname);
NetApiBufferFree(bufptr);
}
}
}
|