Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MsiGetProductInfo不';Don’别给我产品信息_C# - Fatal编程技术网

C# MsiGetProductInfo不';Don’别给我产品信息

C# MsiGetProductInfo不';Don’别给我产品信息,c#,C#,我正在使用下面的代码获取windows应用程序的安装日期。我的应用程序是使用安装程序安装的,它也列在控制面板中。然而,下面的代码并没有得到我的应用程序详细信息。有什么想法吗 [DllImport("msi.dll", CharSet = CharSet.Unicode)] static extern Int32 MsiGetProductInfo(string product, string property, [Out] StringBuilder valueBuf, ref Int3

我正在使用下面的代码获取windows应用程序的安装日期。我的应用程序是使用安装程序安装的,它也列在控制面板中。然而,下面的代码并没有得到我的应用程序详细信息。有什么想法吗

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
static extern Int32 MsiGetProductInfo(string product, string property,
    [Out] StringBuilder valueBuf, ref Int32 len);

[DllImport("msi.dll", SetLastError = true)]
static extern int MsiEnumProducts(int iProductIndex,
    StringBuilder lpProductBuf);

static void Main(string[] args)
{
    StringBuilder sbProductCode = new StringBuilder(39);
    int iIdx = 0;
    while (
        0 == MsiEnumProducts(iIdx++, sbProductCode))
    {
        Int32 productNameLen = 512;
        StringBuilder sbProductName = new StringBuilder(productNameLen);

        MsiGetProductInfo(sbProductCode.ToString(),
            "ProductName", sbProductName, ref productNameLen);

        if (sbProductName.ToString().Contains("MyApplication"))
        {
            Int32 installDirLen = 1024;
            StringBuilder sbInstallDir = new StringBuilder(installDirLen);
            MsiGetProductInfo(sbProductCode.ToString(),
                "InstallLocation", sbInstallDir, ref installDirLen);

            if (sbInstallDir.ToString() != "")
            {
                Console.WriteLine("ProductName {0}: {1}",
                    sbProductName, GetCreationDateOfFolder(sbInstallDir.ToString()).ToString());
            }
        }
    }
}

private static DateTime GetCreationDateOfFolder(string Path)
{
    string directoryString = Path;
    Directory.CreateDirectory(directoryString);
    DateTime dateTime = Directory.GetCreationTime(directoryString);
    return dateTime;
}

详情在登记处。但是,自上次安装以来,您的应用程序名称似乎已更改,或者您无权运行msi函数。我不想从注册表获取!我需要从32位应用程序访问64位注册表。我的更改无效!所以,我切换到这种方法。你有没有考虑过使用WOW6432节点?无论如何,上述方法似乎更干净。我不知道为什么会失败,除非出现拒绝访问错误。我也尝试了Wow6432Node。我的应用程序列在控制面板中。以上代码是否有任何其他要求?您的应用程序是否通过Windows Installer安装(例如由MSI安装)。