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.Shapes;
using Microsoft.Win32;
namespace Demo
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
GetInstallApps();
}
public void GetInstallApps()
{
string uninstallkey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
RegistryKey rk;
using (rk = Registry.LocalMachine.OpenSubKey(uninstallkey))
{
foreach (string skName in rk.GetSubKeyNames())
{
using (RegistryKey sk = rk.OpenSubKey(skName))
{
try
{
lsitBox1.Items.Add(sk.GetValue("DisplayName") + " " + sk.GetValue("DisplayVersion"));
}
catch (Exception ex)
{ }
}
}
// txtblock1.Text = lsitBox1.Items.Count.ToString();
}
}
}
}
应用程序在我的窗口中提供有关所有安装软件的信息,但它包含空格,我想删除该空间,并且我知道它将使用注册密钥注册,因为如果我想删除该特定注册表它将包含空格我能做什么任何想法谢谢
答案 0 :(得分:2)
在尝试catch块之前添加一行
if(sk.GetValue(&#34;&#34;)!= null)