题
这可能听起来有点疯狂,但我怎样才能找到(希望通过 API/注册表项)Windows 的安装时间和日期?
到目前为止我能想到的最好办法就是查看 C:\Windows 中的各种文件并尝试猜测......但这并不是一个很好的解决方案。
解决方案
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
它是自1970年1月1日以来的秒数。
要将该数字转换为可读日期/时间,只需在字段“UNIX TimeStamp:”中粘贴小数值即可。这个 Unix时间转换在线工具。
其他提示
“ 代码挑战 ”的另一个问题:这里有一些源代码可执行文件回答问题,但它们并不完整。
你会找到一个任何人都可以在他/她的计算机上执行的vb脚本,并带有预期的结果吗?
systeminfo|find /i "original"
会给你实际的日期...而不是秒数;)
正如 Sammy 评论, find / i" install"
提供超出您需要的数量。
这只适用于语言环境是英语的:它需要与语言匹配
对于瑞典语,这将是“ ursprungligt
”和“ ursprü ngliches
”对于德国人。
在Windows PowerShell 脚本中,您只需键入:
PS > $os = get-wmiobject win32_operatingsystem
PS > $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy"
使用WMI( Windows Management Instrumentation )
如果您不使用WMI,则必须先读取转换注册表值:
PS > $path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'
PS > $id = get-itemproperty -path $path -name InstallDate
PS > $d = get-date -year 1970 -month 1 -day 1 -hour 0 -minute 0 -second 0
## add to hours (GMT offset)
## to get the timezone offset programatically:
## get-date -f zz
PS > ($d.AddSeconds($id.InstallDate)).ToLocalTime().AddHours((get-date -f zz)) -f "MM/dd/yyyy"
本文的其余部分为您提供了访问相同信息的其他方法。选择你的毒药;)
在VB.Net中可以提供类似的内容:
Dim dtmInstallDate As DateTime
Dim oSearcher As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem")
For Each oMgmtObj As ManagementObject In oSearcher.Get
dtmInstallDate =
ManagementDateTimeConverter.ToDateTime(CStr(oMgmtO bj("InstallDate")))
Next
在 Autoit (Windows脚本语言)中,即:
;Windows Install Date
;
$readreg = RegRead("HKLM\SOFTWARE\MICROSOFT\WINDOWS NT\CURRENTVERSION\", "InstallDate")
$sNewDate = _DateAdd( 's',$readreg, "1970/01/01 00:00:00")
MsgBox( 4096, "", "Date: " & $sNewDate )
Exit
在Delphy 7中,这将是:
Function GetInstallDate: String;
Var
di: longint;
buf: Array [ 0..3 ] Of byte;
Begin
Result := 'Unknown';
With TRegistry.Create Do
Begin
RootKey := HKEY_LOCAL_MACHINE;
LazyWrite := True;
OpenKey ( '\SOFTWARE\Microsoft\Windows NT\CurrentVersion', False );
di := readbinarydata ( 'InstallDate', buf, sizeof ( buf ) );
// Result := DateTimeToStr ( FileDateToDateTime ( buf [ 0 ] + buf [ 1 ] * 256 + buf [ 2 ] * 65535 + buf [ 3 ] * 16777216 ) );
showMessage(inttostr(di));
Free;
End;
End;
打开命令提示符,键入“ systeminfo ”然后按Enter键。您的系统可能需要几分钟才能获得信息。在结果页面中,您将找到一个条目“系统安装日期”。这是Windows安装的日期。此过程适用于XP,Win7以及win8。
如何查找 Windows 7 安装日期/时间:
就看这个...
- 开始>输入CMD
- 输入系统信息
就是这样;然后你就可以看到你的机器的所有信息;非常简单的方法
曾经想知道您的PC操作系统安装日期吗?这是一种快速简便的方法,可以找出安装(或上次升级)PC操作系统的日期和时间。
打开命令提示符(start-> run - >键入cmd->按Enter键)并运行以下命令
systeminfo |查找/ i“安装日期”
几秒钟后,您将看到安装日期
在Powershell中运行命令:
systeminfo | Select-String "Install Date:"
HKLM \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ InstallDate和systeminfo.exe生成 错误的日期 。
UNIX时间戳的定义与时区无关。 UNIX时间戳定义为自1970年1月1日星期四00:00:00协调世界时(UTC)以来经过的秒数,并且不计算闰秒。
换句话说,如果您已经在西雅图,华盛顿州安装了计算机并将其移至纽约州纽约市,HKLM \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ InstallDate将不会反映这一点。这是错误的日期,它不会存储最初安装计算机的时区。
这样做的效果是,如果在运行此程序时更改时区,则日期将是错误的。您必须重新运行可执行文件,以便考虑时区更改。
但是你可以从WMI获得时区信息 Win32_Registry 课程。
根据Microsoft TechNet,InstallDate采用UTC格式(yyyymmddHHMMSS.xxxxxx± UUU)文章”使用WMI处理日期和时间“其中xxxxxx是毫秒和± UUU是与格林威治标准时间不同的分钟数。
private static string RegistryInstallDate()
{
DateTime InstallDate = new DateTime(1970, 1, 1, 0, 0, 0); //NOT a unix timestamp 99% of online solutions incorrect identify this as!!!!
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Registry");
foreach (ManagementObject wmi_Windows in searcher.Get())
{
try
{
///CultureInfo ci = CultureInfo.InvariantCulture;
string installdate = wmi_Windows["InstallDate"].ToString();
//InstallDate is in the UTC format (yyyymmddHHMMSS.xxxxxx±UUU) where critically
//
// xxxxxx is milliseconds and
// ±UUU is number of minutes different from Greenwich Mean Time.
if (installdate.Length==25)
{
string yyyymmddHHMMSS = installdate.Split('.')[0];
string xxxxxxsUUU = installdate.Split('.')[1]; //±=s for sign
int year = int.Parse(yyyymmddHHMMSS.Substring(0, 4));
int month = int.Parse(yyyymmddHHMMSS.Substring(4, 2));
int date = int.Parse(yyyymmddHHMMSS.Substring(4 + 2, 2));
int hour = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2, 2));
int mins = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2 + 2, 2));
int secs = int.Parse(yyyymmddHHMMSS.Substring(4 + 2 + 2 + 2 + 2, 2));
int msecs = int.Parse(xxxxxxsUUU.Substring(0, 6));
double UTCoffsetinMins = double.Parse(xxxxxxsUUU.Substring(6, 4));
TimeSpan UTCoffset = TimeSpan.FromMinutes(UTCoffsetinMins);
InstallDate = new DateTime(year, month, date, hour, mins, secs, msecs) + UTCoffset;
}
break;
}
catch (Exception)
{
InstallDate = DateTime.Now;
}
}
return String.Format("{0:ddd d-MMM-yyyy h:mm:ss tt}", InstallDate);
}
使用speccy。它在“操作系统”部分显示安装日期。 http://www.piriform.com/speccy
您还可以检查系统驱动器中的任何文件夹,例如“windows”等。和“程序文件”。右键单击该文件夹,单击属性,然后在常规选项卡下检查创建文件夹的日期。
在RunCommand中
写 " MSINFO32"
并按Enter键
它将显示与系统
Windows 10操作系统还有另一个注册表子项,这个子项位于SYSTEM配置单元文件中:
> "\Setup\Source OS."
此处的安装日期信息是原始计算机操作系统安装日期/时间。它还会告诉您何时开始更新,即
"\Setup\Source OS (Updated on xxxxxx)."
当然,这可能不是在更新结束时,用户可能会选择关闭而不是在提示时重新启动,等等......
更新实际上可以在另一天完成,
> "\Setup\Source OS (Updated on xxxxxx)"
将反映更新开始的日期/时间。
我发现c:\ pagefile.sys的创建日期在大多数情况下都非常可靠。可以使用此命令轻松获取(假设Windows安装在C:上):
dir /as /t:c c:\pagefile.sys
'/ as'指定'系统文件',否则将无法找到。 '/ t:c'设置时间字段以显示'创建'。
使用WMIC确定Windows安装日期
wmic os get installdate
按 WindowsKey + R 并输入 cmd
在命令窗口中输入:
systeminfo | find /i "Original"
(对于旧版本的Windows,请以全部大写字母键入“ORIGINAL”)。