Can I somehow detect the time when the program was installed using .Net or Win32 api or any other way?
2 Answers
This will get the date of the Installation, I'm not sure of you can get time
string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
using(Microsoft.Win32.RegistryKey key = Registry.LocalMachine.OpenSubKey(registry_key))
{
foreach(string subkey_name in key.GetSubKeyNames())
{
using(RegistryKey subkey = key.OpenSubKey(subkey_name))
{
Console.WriteLine(subkey.GetValue("DisplayName"));
Console.WriteLine(subkey.GetValue("InstallDate"));
}
}
}
you can use all these fields
for more info refer this answer.
you can get time by Using Windows Installer API! the function to be used is MsiGetProductInfo and the property name is INSTALLPROPERTY_INSTALLDATE but WMI is heavyweight.
here is more info for this property taken from here
INSTALLPROPERTY_INSTALLDATE: The last time this product received service. The value of this property is replaced each time a patch is applied or removed from the product or the /v Command-Line Option is used to repair the product. If the product has received no repairs or patches this property contains the time this product was installed on this computer.
Example:
[DllImport("msi.dll", CharSet=CharSet.Unicode)]
static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int32 len);
Int32 len = 512;
System.Text.StringBuilder builder = new System.Text.StringBuilder(len);
MsiGetProductInfo("{4B3334CE-06D9-4446-BBC5-EB4C9D75BFF6}", "INSTALLPROPERTY_INSTALLDATE", builder , ref len);
You have to find it in registry.
Thats why its not about .NET
or WinAPI
.
For example:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\InstallDate
shows you the istallation time of your Windows
in seconds since 01.01.1970

- 6,705
- 7
- 39
- 74