System.Management.ObjectQuery MyQuery = new System.Management.ObjectQuery("SELECT * FROM Win32_OperatingSystem");
System.Management.ManagementScope MyScope = new System.Management.ManagementScope();
ManagementObjectSearcher MySearch = new ManagementObjectSearcher(MyScope, MyQuery);
ManagementObjectCollection MyCollection = MySearch.Get();
string StrInfo = "";
foreach (ManagementObject MyObject in MyCollection)
{
StrInfo = MyObject.GetText(TextFormat.Mof);
}
string InstallDate = StrInfo.Substring(StrInfo.LastIndexOf("InstallDate") + 15, 14);
Console.Write("系统安装时间:" + InstallDate);
需要引入命名空间 System.Management。