【发布时间】:2008-10-04 16:36:15
【问题描述】:
这听起来有点像一个疯狂的问题,但我如何才能(希望通过 API/注册表项)找出 Windows 的安装时间和日期?
到目前为止,我能想到的最好办法是查看 C:\Windows 中的各种文件并尝试猜测......但这并不是一个很好的解决方案。
【问题讨论】:
标签: windows installation
这听起来有点像一个疯狂的问题,但我如何才能(希望通过 API/注册表项)找出 Windows 的安装时间和日期?
到目前为止,我能想到的最好办法是查看 C:\Windows 中的各种文件并尝试猜测......但这并不是一个很好的解决方案。
【问题讨论】:
标签: windows installation
重要提示如果 Windows 是使用磁盘映像“安装”,这两种方法都会失败。
方法 1 在 windows 尚未升级到新的主要版本(例如 windows 10 到 windows 11)时有效。您执行命令systeminfo 并查找以“原始安装日期”(或您的本地语言中的类似内容)开头的行。您可以通过查询 WMI 和查看注册表来获得相同的版本。如果 Windows 升级到新的主要版本,不幸的是,此方法会为您提供新主要版本的安装日期。下面是一个通过 PowerShell 运行 systeminfo 来检查版本的示例:
systeminfo | sls "original"
方法 2 即使在重大更新之后,这似乎也能正常工作。您可以通过检查文件system.ini 的创建时间来获得安装日期,该文件似乎保持不变。例如使用 PowerShell:
(Get-Item "C:\Windows\system.ini").CreationTime
另一个符合“code-challenge”的问题:这里有一些源代码可执行文件来回答这个问题,但它们并不完整。
你会找到一个任何人都可以在他/她的计算机上执行的 vb 脚本,并获得预期的结果吗?
systeminfo|find /i "original"
会给你实际的日期...而不是秒数;)
但是(警告),如the 2021 comments Salman A 和 AutoMattTick 中所述
如果 Windows 已更新到较新版本,这似乎给出了重新安装 Windows 的日期。
作为Sammy comments,find /i "install" 提供的超出您的需要。
这仅在语言环境为英语时才有效:它需要与语言匹配。
对于瑞典语,这将是“ursprungligt”和“ursprüngliches”对于德语。
用
减少5个字符systeminfo|find "Original"
在 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;
作为替代方案,CoastN 建议 in the comments:
由于
system.ini-file在典型的 Windows 部署中保持不变,您实际上可以使用以下 oneliner 获取安装日期:(PowerShell): (Get-Item "C:\Windows\system.ini").CreationTime
【讨论】:
systeminfo|find /i "original" 仅过滤“原始安装日期”。如果您使用“安装”作为字符串,您将获得比您需要的更多信息。此外,如果语言环境不是英语,那么这可能不起作用。它需要匹配语言。对于瑞典语,这将是 "ursprungligt" 和 "ursprüngliches" 对于德语。
在regedit.exe 中转至:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
它以自 1970 年 1 月 1 日以来的秒数给出。(注意:对于 Windows 10,此日期将是最后一次功能更新的安装日期,而不是原始安装日期。)
要将该数字转换为可读的日期/时间,只需将十进制值粘贴到此Unix Time Conversion online tool 的“UNIX 时间戳:”字段中。
【讨论】:
我们在这里有足够的答案,但我想投入我的 5 美分。
在我之前的安装之上,我在10/30/2015 上安装了 Windows 10,并在 04/14/2017 上安装了 Creators Update。我之前的答案中描述的所有方法都为我提供了 Creators Update 的安装日期。
我设法找到了几个文件的创建日期与我的 Windows 10 的真实(干净)安装日期相匹配:
C:\Windows
C:\
顺便说一句,在 C:\ 和 C:\windows 中获取 10 个最旧(通过创建)文件的简单方法是在管理 powershell 会话上运行这两个命令:
dir -Force C:\ | sort -Property creationtime | select -Property name, creationtime -First 10
dir -Force C:\windows | sort -Property creationtime | select -Property name, creationtime -First 10
【讨论】:
system.ini 的日期在我的 Windows 7 和 2008 机器上没有意义,看来安装源中创建的时间戳正在安装时被复制。 C:\pagefile.sys 的时间戳正确。
打开命令提示符,输入“systeminfo”并按回车键。您的系统可能需要几分钟才能获取信息。在结果页面中,您将找到“系统安装日期”条目。那是windows安装的日期。此过程适用于XP、Win7和win8。
【讨论】:
如何找出 Windows 7 的安装日期/时间:
看看这个……
就是这样;然后您可以看到有关您的机器的所有信息;很简单的方法
【讨论】:
想知道您 PC 的操作系统安装日期吗?这是查找您的 PC 操作系统安装(或上次升级)的日期和时间的快速简便方法。
打开命令提示符(开始->运行->输入cmd->回车)并运行以下命令
系统信息 |查找 /i "安装日期"
几秒钟后,您将看到安装日期
【讨论】:
在 Powershell 中运行命令:
systeminfo | Select-String "Install Date:"
【讨论】:
find /i
Windows 10 操作系统还有另一个注册表子键,这个在 SYSTEM hive 文件中:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\
此处的安装日期信息是原始计算机操作系统的安装日期/时间。它还会告诉您更新何时开始,即
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on xxxxxx)."
这当然可能不是更新结束的时候,用户可能会在提示时选择关闭而不是重新启动,等等......
更新实际上可以在不同的日子完成,并且
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on xxxxxx)"
将反映开始更新的日期/时间。
【讨论】:
我发现 c:\pagefile.sys 的创建日期在大多数情况下是相当可靠的。使用这个命令可以轻松获取(假设Windows安装在C:):
dir /as /t:c c:\pagefile.sys
“/as”指定“系统文件”,否则找不到。 '/t:c' 将时间字段设置为显示'creation'。
【讨论】:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate 和 systeminfo.exe 生成 wrong date。
UNIX 时间戳的definition 与时区无关。 UNIX 时间戳定义为自 1970 年 1 月 1 日星期四 00:00:00 协调世界时 (UTC) 以来经过的秒数,不包括闰秒。
换句话说,如果您将计算机安装在华盛顿州西雅图并搬到纽约,则 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate 将不会反映这一点。这是错误的日期,它不存储最初安装计算机的时区。
这样做的效果是,如果你在运行这个程序的时候改变了时区,日期就会出错。您必须重新运行可执行文件,以便它考虑时区更改。
但您可以从 WMI Win32_Registry 类中获取时区信息。
InstallDate 采用 UTC 格式 (yyyymmddHHMMSS.xxxxxx±UUU),根据 Microsoft TechNet article“使用 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);
}
【讨论】:
使用 WMIC 确定 Windows 安装日期
wmic os 获取安装日期
【讨论】:
PowerShell 非常简单的方法:
(Get-CimInstance -Class Win32_OperatingSystem).InstallDate
摘自:https://www.sysadmit.com/2019/10/windows-cuando-fue-instalado.html
【讨论】:
使用规范。它在操作系统部分显示安装日期。 http://www.piriform.com/speccy
【讨论】:
您还可以检查系统驱动器中的任何文件夹,例如“windows”和“程序文件”。右键单击文件夹,单击属性并在常规选项卡下检查文件夹的创建日期。
【讨论】:
.WIM 文件),创建日期是 Microsoft 创建映像的时间,而不是操作系统安装在特定计算机上的时间。跨度>
在运行命令中
写 "MSINFO32" 并回车
它将显示与系统相关的所有信息
【讨论】:
您可以简单地检查 Windows 文件夹的创建日期(右键单击它并检查属性) :)
【讨论】:
在尝试了各种方法后,我发现系统卷的NTFS卷创建时间可能是最好的代理。虽然有工具可以检查这一点(请参阅this link),但我想要一种没有额外实用程序的方法。我确定了“C:\System Volume Information”的创建日期,似乎在各种情况下都检查出来了。
一行 PowerShell 获取它是:
([DateTime](Get-Item -Force 'C:\System Volume Information\').CreationTime).ToString('MM/dd/yyyy')
【讨论】:
按 WindowsKey + R 并输入cmd
在命令窗口输入:
systeminfo | find /i "Original"
(对于旧版本的 Windows,请输入全部大写的“ORIGINAL”)。
【讨论】:
您可以使用 PowerShell 做到这一点:
Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\' -Name InstallDate |
Select-Object -Property @{n='InstallDate';e={[DateTime]::new(1970,1,1,0,0,0,0,'UTC').AddSeconds($_.InstallDate).ToLocalTime()}}
【讨论】:
试试这个 powershell 命令:
Get-ChildItem -Path HKLM:\System\Setup\Source* |
ForEach-Object {Get-ItemProperty -Path Registry::$_} |
Select-Object ProductName, ReleaseID, CurrentBuild, @{n="Install Date"; e={([DateTime]'1/1/1970').AddSeconds($_.InstallDate)}} |
Sort-Object "Install Date"
【讨论】: