从这个网站,使用注册表而不是WMI(未经测试):
public static DateTime GetWindowsInstallationDateTime(string computerName)
{
Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, computerName);
key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
if (key != null)
{
DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
DateTime installDate = startDate.AddSeconds(regVal);
return installDate;
}
return DateTime.MinValue;
}
Run Code Online (Sandbox Code Playgroud)