c# 如何获取操作系统的安装时间,我要的是代码里怎么写,而不是如何查看。
1个回答
展开全部
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。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询