wpf中的控制面板c#

时间:2015-01-19 11:30:16

标签: c# wpf winforms xaml wpftoolkit

我想在windows系列中创建类似控制面板的应用程序。我尝试使用dis代码我从regedit(注册表项)中检索所有信息。 它的Retriving很长的清单。
1)我不知道将它绑定到xaml.2。我可以通过我的wpf应用程序卸载。 代码正在检索有关卸载程序的信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;

namespace InstallPrograms
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        const string registry_key = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
        public MainWindow()
        {
            InitializeComponent();

            getInstallPrograms();


        }
        public static List<string> getInstallPrograms()
        {
            var result = new List<string>();
            result.AddRange(getAllInstallProgramsFromRegistry(RegistryView.Registry32));
            result.AddRange(getAllInstallProgramsFromRegistry(RegistryView.Registry64));
            return result;
        }
        private static IEnumerable<string> getAllInstallProgramsFromRegistry(RegistryView registeryView)
        {
            var result = new List<string>();
            RegistryKey key ;
           using(key= RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registeryView).OpenSubKey(registry_key))
            {
                foreach (string subkey_name in key.GetSubKeyNames())
                {
                    using (RegistryKey subkey = key.OpenSubKey(subkey_name))
                    {
                        if (IsProgramVisible(subkey))
                        {
                            result.Add((string)subkey.GetValue("DisplayName"));
                            result.Add((string)subkey.GetValue("ReleaseType"));
                            result.Add((string)subkey.GetValue("ParentDisplayName"));
                        }
                    }
                }
            }
            return result;
        }
        public static bool IsProgramVisible(RegistryKey subkey)
        {
            var name = (string)subkey.GetValue("DisplayName");
            var releaseType = (string)subkey.GetValue("ReleaseType");
            var systemComponent = subkey.GetValue("SystemComponent");
            var uninstallString = (string)subkey.GetValue("UninstallString");
            var parentName = (string)subkey.GetValue("ParentDisplayName");
            return
                !string.IsNullOrEmpty(name)
                && string.IsNullOrEmpty(releaseType)
                && string.IsNullOrEmpty(uninstallString)
                && string.IsNullOrEmpty(parentName)
                && (systemComponent == null);
        }

        }
    }

0 个答案:

没有答案