检测程序安装时间 [英] Detecting the time when the program was installed

查看:37
本文介绍了检测程序安装时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能否以某种方式检测使用 .Net 或 Win32 api 或任何其他方式安装程序的时间?

Can I somehow detect the time when the program was installed using .Net or Win32 api or any other way?

推荐答案

这会得到安装的日期,我不确定你能得到时间

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.

您可以通过使用 Windows Installer API 获得时间!要使用的函数是 MsiGetProductInfo 且属性名称为 INSTALLPROPERTY_INSTALLDATE,但 WMI 是重量级的.

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.

这里是从 这里

INSTALLPROPERTY_INSTALLDATE:该产品上次接受服务的时间.每次在产品中应用或删除补丁或使用/v 命令行选项修复产品时,都会替换此属性的值.如果产品未收到任何修复或补丁,则此属性包含此产品在此计算机上的安装时间.

示例:

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

这篇关于检测程序安装时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆