using System;
using System.Collections.Generic;
using System.Text;
using System.Management;
using System.Runtime.InteropServices;
namespace OPurchase
{
public class SystemInfo
{
/// <summary>
/// 查询CPU编号
/// </summary>
///
[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
public static extern int GetSystemDefaultLCID();
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
public const int LOCALE_SLONGDATE = 0x20;
public const int LOCALE_SSHORTDATE = 0x1F;
public const int LOCALE_STIME = 0x1003;
public void SetDateTimeFormat()
{
try
{
int x = GetSystemDefaultLCID();
SetLocaleInfo(x, LOCALE_STIME, "HH:mm:ss"); //时间格式
SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-MM-dd"); //短日期格式
SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy-MM-dd"); //长日期格式
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
public string GetCpuId()
{
ManagementClass mClass = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mClass.GetInstances();
string cpuId = null;
foreach (ManagementObject mo in moc)
{
cpuId = mo.Properties["ProcessorId"].Value.ToString();
break;
}
return cpuId;
}
/// <summary>
/// 查询硬盘编号
/// </summary>
public string GetMainHardDiskId()
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
String strHardDiskID = null;
foreach (ManagementObject mo in searcher.Get())
{
strHardDiskID = mo["SerialNumber"].ToString().Trim();
break;
}
return strHardDiskID;
}
catch
{
return "";
}
}
}
}