Good afternoon,
I'm new to c# and pulled a code yesterday to convert the Original Install Date for my operating system from the registry D Word to a DateTime output. Now the code does do what it's supposed to do except display the actual date (instead shows the default date of 1/1/1970). There is a snippet in the code that should convert the D Word (which is the seconds after that default date as designated by Microsoft) to give you the actual OS install date but it does not. This is the code as follows:
and this is how I call it into the application:
string scomputer = System.Environment.MachineName;
SosDate.Text = GetWindowsInstallationDateTime(scomputer).ToString();
Any help is appreciated!
I'm new to c# and pulled a code yesterday to convert the Original Install Date for my operating system from the registry D Word to a DateTime output. Now the code does do what it's supposed to do except display the actual date (instead shows the default date of 1/1/1970). There is a snippet in the code that should convert the D Word (which is the seconds after that default date as designated by Microsoft) to give you the actual OS install date but it does not. This is the code as follows:
C#:
public static DateTime GetWindowsInstallationDateTime(string scomputer) {
Microsoft.Win32.RegistryKey key = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, scomputer);
key = key.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", false);
if (key != null)
{
DateTime startDate = new DateTime(1970, 1, 1, 0, 0, 0);
Int64 regVal = Convert.ToInt64(key.GetValue("InstallDate").ToString());
DateTime installDate = startDate.AddSeconds(regVal);
return installDate;
}
return DateTime.MinValue;
}
and this is how I call it into the application:
string scomputer = System.Environment.MachineName;
SosDate.Text = GetWindowsInstallationDateTime(scomputer).ToString();
Any help is appreciated!