3

名前を取得するこのコードがありますが、各プログラムのアイコンを取得するにはどうすればよいですか?

 string SoftwareKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Installer\\UserData\\S-1-5-18\\Products";
        RegistryKey rk = default(RegistryKey);
        rk = Registry.LocalMachine.OpenSubKey(SoftwareKey);

        string sname = string.Empty;

        foreach (string skname in rk.GetSubKeyNames())
        {

            try
            {
                sname = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("DisplayName").ToString();
                string Inst1 = Registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("InstallLocation").ToString();
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[2].Value = sname; 
                dataGridView1.Rows[n].Cells[3].Value = Inst1;
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
            }
        }
4

2 に答える 2

4

インストールされた実行可能ファイルが提供されるかどうかはわかりませんInstallProperties(実際、インストーラーは複数の実行可能ファイルをインストールできるため)。

正しい実行可能ファイルを特定する手段がある場合 (.exe ファイルを列挙するなどInstallLocation)、その .exe から既定のアイコンを取得できます。

詳細については、

シェルが使用するファイル アイコンを取得する

アップデート

次のコードはテストされていませんが、かなり近いものになるはずです。

string Inst1 = registry.LocalMachine.OpenSubKey(SoftwareKey).OpenSubKey(skname).OpenSubKey("InstallProperties").GetValue("InstallLocation").ToString();

foreach (string file in Directory.GetFiles(Inst1, "*.exe")) 
{
    string filePath = Path.Combine(Inst1, file);
    Icon  result = Icon.ExtractAssociatedIcon(filePath);
    // If result is not null, you have an icon.
}
于 2012-07-04T06:35:16.617 に答える
2

これを試して:

Icon  result = Icon.ExtractAssociatedIcon(filePath); 
于 2012-07-04T06:40:51.300 に答える