1

インストール フォルダー、アンインストール文字列、バージョン番号など、特定のインストール済みアプリケーションからデータを取得しようとしています。次のコードを実行すると、インストール フォルダーは取得されますが、UninstallString 値に対して 4 行の疑問符が返されます. 何か案は?

    public static void FindInstalled(string AppName)
    {
        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(AppName))
            {
                Int32 installDirLen = 1024;
                StringBuilder sbInstallDir = new StringBuilder(installDirLen);

                MsiGetProductInfo(sbProductCode.ToString(), "InstallLocation", sbInstallDir, ref installDirLen);
                Console.Writeline("Install Directory - {0}",sbInstallDir.ToString());

                MsiGetProductInfo(sbProductCode.ToString(), "UninstallString", sbInstallDir, ref installDirLen); 
                Console.Writeline("Uninstall String - {0}", sbInstallDir.ToString());

            }
        }
    }
4

2 に答える 2

1

UninstallString は有効なプロパティではありません。有効なプロパティの一覧については、 http://msdn.microsoft.com/en-us/library/aa370130( VS.85 ).aspx を参照してください。

Windows インストーラーのヘッダー ファイル ("msi.h") を開いてテキスト "UninstallString" を検索しても、見つかりません。また、http://msdn.microsoft.com/en-us/library/aa370905( VS.85 ).aspxのプロパティ リファレンスを調べて、そのページで「UninstallString」を検索しても、見つかりません。

私のアドバイスは、代わりにレジストリからプロパティを読み取ることです。詳細については、 http://msdn.microsoft.com/en-us/library/aa372105 (VS.85).aspxを参照してください。そこから必要な詳細を取得できます。

于 2011-08-26T14:45:18.947 に答える
0

How about something like this:

    public static void FindInstalled(AppName)
    {
        RegistryKey myRegKey = Registry.LocalMachine;
        myRegKey = myRegKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
        String[] subkeyNames = myRegKey.GetSubKeyNames();
        foreach (String s in subkeyNames)
        {
            RegistryKey UninstallKey = Registry.LocalMachine;
            UninstallKey = UninstallKey.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + s);
            Object oValue = UninstallKey.GetValue("DisplayName");

            if (oValue != null)
            {
                if (oValue.ToString() == AppName)
                {
                    oValue = UninstallKey.GetValue("UninstallString");
                    Console.Writeline("Uninstall URL - {0}", oValue.ToString());
                    break;
                }
            }
        }
    }
于 2011-08-26T15:03:37.750 に答える