如何找到 Windows 的安装时间和日期?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/170617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find the install time and date of Windows?
提问by Free Wildebeest
This might sound like a little bit of a crazy question, but how can I find out (hopefully via an API/registry key) the install time and date of Windows?
这听起来有点像一个疯狂的问题,但我如何才能(希望通过 API/注册表项)找出 Windows 的安装时间和日期?
The best I can come up with so far is to look at various files in C:\Windows and try to guess... but that's not exactly a nice solution.
到目前为止,我能想到的最好方法是查看 C:\Windows 中的各种文件并尝试猜测……但这并不是一个很好的解决方案。
采纳答案by Tommy
In regedit.exe
go to:
在regedit.exe
去:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
It's given as the number of seconds since January 1, 1970. (Note: for Windows 10, this date will be when the last feature update was installed, not the original install date.)
它以自 1970 年 1 月 1 日以来的秒数形式给出。(注意:对于 Windows 10,此日期将是最后一次功能更新的安装日期,而不是原始安装日期。)
To convert that number into a readable date/time just paste the decimal value in the field "UNIX TimeStamp:" of this Unix Time Conversion online tool.
要将这个数字转换为可读的日期/时间,只需将十进制值粘贴到此Unix 时间转换在线工具的“UNIX 时间戳:”字段中。
回答by VonC
Another question elligeable for a 'code-challenge': here are some source code executables to answer the problem, but they are not complete.
Will you find a vb script that anyone can execute on his/her computer, with the expected result ?
另一个“代码挑战”的问题:这里有一些源代码可执行文件来回答这个问题,但它们并不完整。
你会找到一个任何人都可以在他/她的计算机上执行的 vb 脚本,并得到预期的结果吗?
systeminfo|find /i "original"
would give you the actual date... not the number of seconds ;)
As Sammycomments, find /i "install"
gives more than you need.
And this only works if the locale is English: It needs to match the language.
For Swedish this would be "ursprungligt
" and "ursprüngliches
" for German.
会给你实际日期......而不是秒数;)
正如Sammy评论的那样,find /i "install"
给出的比你需要的多。
这仅在语言环境为英语时才有效:它需要匹配语言。
对于瑞典语,这将是“ ursprungligt
”和“ ursprüngliches
”德语。
In Windows PowerShellscript, you could just type:
在 Windows PowerShell脚本中,您只需键入:
PS > $os = get-wmiobject win32_operatingsystem
PS > $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy"
By using WMI (Windows Management Instrumentation)
通过使用 WMI(Windows 管理规范)
If you do not use WMI, you must read then convert the registry value:
如果不使用 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"
The rest of this post gives you other ways to access that same information. Pick your poison ;)
这篇文章的其余部分为您提供了访问相同信息的其他方法。选择你的毒药;)
In VB.Net that would give something like:
在 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
In Autoit(a Windows scripting language), that would be:
在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
In Delphy 7, that would go as:
在 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;
As an alternative, CoastNproposes in the comments:
As the
system.ini-file
stays untouched in a typical windows deployment, you can actually get the install-date by using the following oneliner:(PowerShell): (Get-Item "C:\Windows\system.ini").CreationTime
由于
system.ini-file
在典型的 Windows 部署中保持不变,您实际上可以使用以下 oneliner 获取安装日期:(PowerShell): (Get-Item "C:\Windows\system.ini").CreationTime
回答by Nikolay Kostov
We have enough answers here but I want to put my 5 cents.
我们这里有足够的答案,但我想投入 5 美分。
I have Windows 10 installed on 10/30/2015
and Creators Update installed on 04/14/2017
on top of my previous installation. All of the methods described in the answers before mine gives me the date of the Creators Update installation.
我安装了 Windows 10,10/30/2015
并04/14/2017
在我之前的安装基础上安装了Creators Update 。在我之前的答案中描述的所有方法都为我提供了 Creators Update 安装的日期。
I've managed to find few files` date of creation which matches the real (clean) installation date of my Windows 10:
我设法找到了几个文件的创建日期与我的 Windows 10 的真实(干净)安装日期相匹配:
- in
C:\Windows
- 在
C:\Windows
- in
C:\
- 在
C:\
回答by diptangshu sengupta
Open command prompt, type "systeminfo" and press enter. Your system may take few mins to get the information. In the result page you will find an entry as "System Installation Date". That is the date of windows installation. This process works in XP ,Win7 and also on win8.
打开命令提示符,输入“ systeminfo”并按回车键。您的系统可能需要几分钟才能获取信息。在结果页面中,您将找到“系统安装日期”条目。那是windows安装的日期。此过程适用于 XP、Win7 和 Win8。
回答by ani alexander
How to find out Windows 7 installation date/time:
如何找出 Windows 7 安装日期/时间:
just see this...
看看这个...
- start > enter CMD
- enter systeminfo
- 开始 > 输入 CMD
- 输入系统信息
that's it; then you can see all information about your machine; very simple method
就是这样; 然后您可以看到有关您机器的所有信息;非常简单的方法
回答by Robin
Ever wanted to find out your PC's operating system installation date? Here is a quick and easy way to find out the date and time at which your PC operating system installed(or last upgraded).
曾经想知道您的 PC 的操作系统安装日期吗?这是一种快速简便的方法,可以找出您的 PC 操作系统安装(或上次升级)的日期和时间。
Open the command prompt (start-> run -> type cmd-> hit enter) and run the following command
打开命令提示符(开始->运行->输入cmd->回车)并运行以下命令
systeminfo | find /i "install date"
系统信息 | 找到/i“安装日期”
In couple of seconds you will see the installation date
几秒钟后,您将看到安装日期
回答by user3827180
In Powershell run the command:
在 Powershell 中运行命令:
systeminfo | Select-String "Install Date:"
回答by Amit Gupta
Windows 10 OS has yet another registry subkey, this one in the SYSTEM hive file:
Windows 10 操作系统还有另一个注册表子项,该子项位于 SYSTEM hive 文件中:
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\
The Install Date information here is the original computer OS install date/time. It also tells you when the update started, ie
此处的安装日期信息是原始计算机操作系统安装日期/时间。它还告诉您更新何时开始,即
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on xxxxxx)."
This may of course not be when the update ends, the user may choose to turn off instead of rebooting when prompted, etc...
这当然可能不是在更新结束时,用户可以在提示时选择关闭而不是重新启动等......
The update can actually complete on a different day, and
更新实际上可以在不同的日子完成,并且
Computer\HKEY_LOCAL_MACHINE\SYSTEM\Setup\Source OS (Updated on xxxxxx)"
will reflect the date/time it started the update.
将反映开始更新的日期/时间。
回答by Markus
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate and systeminfo.exe produces the wrong date.
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate 和 systeminfo.exe 产生错误的日期。
The definitionof UNIX timestamp is timezone independent. The UNIX timestamp is defined as the number of seconds that have elapsed since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970 and not counting leap seconds.
UNIX 时间戳的定义与时区无关。UNIX 时间戳定义为自 1970 年 1 月 1 日星期四 00:00:00 协调世界时 (UTC) 以来经过的秒数,不计算闰秒。
In other words, if you have installed you computer in Seattle, WA and moved to New York,NY the HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate will not reflect this. It's the wrong date, it doesn't store timezone where the computer was initially installed.
换句话说,如果您已在华盛顿州西雅图安装计算机并搬到纽约州纽约市,则 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate 将不会反映这一点。这是错误的日期,它不存储最初安装计算机的时区。
The effect of this is, if you change the timezone while running this program, the date will be wrong. You have to re-run the executable, in order for it to account for the timezone change.
这样做的结果是,如果您在运行此程序时更改时区,日期将是错误的。您必须重新运行可执行文件,以便它考虑时区更改。
But you can get the timezone info from the WMI Win32_Registryclass.
但是您可以从 WMI Win32_Registry类中获取时区信息。
InstallDate is in the UTC format (yyyymmddHHMMSS.xxxxxx±UUU) as per Microsoft TechNet article"Working with Dates and Times using WMI" where notably xxxxxx is milliseconds and ±UUU is number of minutes different from Greenwich Mean Time.
根据 Microsoft TechNet文章“使用 WMI 处理日期和时间”,InstallDate 采用 UTC 格式 (yyyymmddHHMMSS.xxxxxx±UUU),其中 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);
}
回答by MoonDogg
I find the creation date of c:\pagefile.sys can be pretty reliable in most cases. It can easily be obtained using this command (assuming Windows is installed on C:):
我发现 c:\pagefile.sys 的创建日期在大多数情况下非常可靠。可以使用以下命令轻松获取它(假设 Windows 安装在 C: 上):
dir /as /t:c c:\pagefile.sys
The '/as' specifies 'system files', otherwise it will not be found. The '/t:c' sets the time field to display 'creation'.
'/as' 指定'系统文件',否则找不到。'/t:c' 将时间字段设置为显示 'creation'。