使用Office键填充ListView的问题

时间:2014-07-24 15:50:31

标签: c#

我正在为我的项目使用ListView,它找到已安装的程序,Windows键和办公室键。问题是在ListView上定位,解密和显示解码的密钥。代码正在寻找我想要它的所有Office版本,但是如何在ListView中显示结果? String正在处理其他搜索,但byte[]没有。找到办公室版本的代码是:

namespace MSOfficeKeyDecoder
{
public class OfficeKeyDecoder
{        
    public enum Key { XP, Office, Office10, Office10X64, Office11, Office11X64, Office12, Office12X64, Office13, Office13X64, Office14, Office14X64, Office15, Office15X64 };
    public static byte[] GetRegistryDigitalProductId(Key key)
    {
        byte[] DigitalProductId = null;
        RegistryKey registry = null;
        switch (key)
        {
            // Open the Office 10 subkey readonly.
            case Key.Office10:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\\\Microsoft\\Office\\10.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office11:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Microsoft\\Office\\11.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office12:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Microsoft\\Office\\12.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office13:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Microsoft\\Office\\13.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office14:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Microsoft\\Office\\14.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office15:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Microsoft\\Office\\15.0\\Registration\\",
                      false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office10X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\10.0\\Registration\\",
                      false);
                break;

            // Open the Office 11 subkey readonly.
            case Key.Office11X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\11.0\\Registration\\",
                      false);
                break;

            // Open the Office 12 subkey readonly.
            case Key.Office12X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\12.0\\Registration\\",
                      false);
               break;

            // Open the Office 13 subkey readonly.
            case Key.Office13X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\13.0\\Registration\\",
                      false);
               break;

            // Open the Office 11 subkey readonly.
            case Key.Office14X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\14.0\\Registration\\{91140000-0011-0000-0000-0000000FF1CE}",
                     false);
                break;

            // Open the Office 10 subkey readonly.
            case Key.Office15X64:
                registry =
                  Registry.LocalMachine.
                    OpenSubKey("SOFTWARE\\Wow6432Node\\Microsoft\\Office\\15.0\\Registration\\",
                      false);
                 // TODO: Open the registry key.
                 break;
        }
        if (registry != null)
        {
            // TODO: For other products, key name maybe different.
            DigitalProductId = registry.GetValue("DigitalProductId") as byte[];
            registry.Close();
        }
        return DigitalProductId;
    }
}
}

然后在ListView中:

byte[] result1 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office10);
byte[] result2 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office11);
byte[] result3 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office12);
byte[] result4 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office13);   
byte[] result5 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office14);
byte[] result6 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office15);
byte[] result7 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office10X64);
byte[] result8 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office11X64);
byte[] result9 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office12X64);
byte[] result10 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office13X64);
byte[] result11 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office14X64);
byte[] result12 = OfficeKeyDecoder.GetRegistryDigitalProductId(OfficeKeyDecoder.Key.Office15X64);
//
//
// ListView Control:
//
//
ListViewItem row2 = new ListViewItem(String.Format(OfficeNameDecoder.ProductName));
row2.SubItems.Add(String.Format(OfficeProductIDDecoder.ProductID));
row2.SubItems.Add(String.Format(OfficeVersionDecoder.ProductVersion));
row2.SubItems.Add(String.Format(OfficeKeyDecoder.DecodeOfficeKey(result11))); 

ProgramsLvw.Items.Add(row2);

结果11是x64系统上的Office 2010。如果我使用结果1到10,我会得到一个空引用。

0 个答案:

没有答案