How do I find the install time and date of Windows

2019-01-12 19:58发布

问题:

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?

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.

回答1:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate

It's given as the number of seconds since January 1, 1970.

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.



回答2:

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 ?


systeminfo|find /i "original" 

would give you the actual date... not the number of seconds ;)
As Sammy comments, 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.


In Windows PowerShell script, you could just type:

PS > $os = get-wmiobject win32_operatingsystem
PS > $os.ConvertToDateTime($os.InstallDate) -f "MM/dd/yyyy" 

By using WMI (Windows Management Instrumentation)

If you do not use WMI, you must read then convert the registry value:

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:

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:

;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:

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;


回答3:

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.



回答4:

We have enough answers here but I want to put my 5 cents.

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.

I've managed to find few files` date of creation which matches the real (clean) installation date of my Windows 10:

  • in C:\Windows

  • in C:\



回答5:

How to find out Windows 7 installation date/time:

just see this...

  • start > enter CMD
  • enter systeminfo

that's it; then you can see all information about your machine; very simple method



回答6:

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).

Open the command prompt (start-> run -> type cmd-> hit enter) and run the following command

systeminfo | find /i "install date"

In couple of seconds you will see the installation date



回答7:

In Powershell run the command:

systeminfo | Select-String "Install Date:"


回答8:

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:):

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'.



回答9:

You can also check the check any folder in the system drive like "windows" and "program files". Right click the folder, click on the properties and check under the general tab the date when the folder was created.



回答10:

Windows 10 OS has yet another registry subkey, this one in the SYSTEM hive file:

> "\Setup\Source OS."

The Install Date information here is the original computer OS install date/time. It also tells you when the update started, ie

 "\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

> "\Setup\Source OS (Updated on xxxxxx)"

will reflect the date/time it started the update.



回答11:

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate and systeminfo.exe produces the wrong date.

The definition of 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.

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.

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_Registry class.

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.

 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);      
    }


回答12:

Use speccy. It shows the installation date in Operating System section. http://www.piriform.com/speccy



回答13:

In RunCommand write "MSINFO32" and hit enter It will show All information related to system



回答14:

Determine the Windows Installation Date with WMIC

wmic os get installdate



回答15:

Press WindowsKey + R and enter cmd

In the command window type:

systeminfo | find /i "Original"

(for older versions of windows, type "ORIGINAL" in all capital letters).