Bill Gim
Bill Gim

Reputation: 33

Can I get the Original Install Date of the Windows using C#?

How can I get the Original Install Date of the Windows using C#?

Upvotes: 3

Views: 6529

Answers (2)

Bridge
Bridge

Reputation: 30651

From this website, using the registry rather than WMI (untested):

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 installDate = 
            DateTime.FromFileTimeUtc(
                Convert.ToInt64(
                    key.GetValue("InstallDate").ToString()));
 
        return installDate;
    }
 
    return DateTime.MinValue;
}

Upvotes: 9

Markus
Markus

Reputation: 438

The HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate is the Windows InstallDate using a Unix timestamp, but technically it's the wrong date.

Let me explain;

The definition of UNIX timestamp is time zone 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 give you the date in NY timezone, not in Seattle timezone where Windows was original installed. It's the wrong date, it doesn't store timezone where the computer was initially installed.

Solution

  1. Change you computer time zone (right-click on you clock->Adjust date/time->Adjust time zone) to the time zone where windows was installed, or first turned on. Then run systeminfo.exe find /i "Original Install Date"
  2. HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate but you have add the time zone where windows was installed, or first turned on.

Upvotes: 1

Related Questions