62,046
社区成员
发帖
与我相关
我的任务
分享
[DllImport("kernel32",EntryPoint="GetComputerNameA", ExactSpelling=true, CharSet=CharSet.Ansi, SetLastError=true)]
public static extern int GetComputerName(string lpBuffer, ref int nSize);
[DllImport("kernel32", EntryPoint = "GetComputerName", ExactSpelling = false, SetLastError = true)]
public static extern bool GetComputerName([MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer, [MarshalAs(UnmanagedType.LPArray)] Int32[] nSize);
public static string gsFNC_GetComputerName()
{
string returnValue;
byte[] str = new byte[255];
Int32[] len = new Int32[1];
len[0] = 200;
GetComputerName(str, len);
string ComputerName = System.Text.Encoding.ASCII.GetString(str);
returnValue = ComputerName.Substring(0,ComputerName.IndexOf('\0'));
return returnValue;
}