注册表安装的程序包含 space
Registery install programs containing space
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();
}
}
}
}
应用程序提供有关我 windows 中所有安装软件的信息,但它包含 space,我想删除那个 space,而且我知道它将使用注册表键注册,因为如果我想删除那个特定的注册表,它将包含 space 我能做些什么谢谢你
在 try catch 块之前添加一行
if (sk.GetValue("") != null)
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();
}
}
}
}
应用程序提供有关我 windows 中所有安装软件的信息,但它包含 space,我想删除那个 space,而且我知道它将使用注册表键注册,因为如果我想删除那个特定的注册表,它将包含 space 我能做些什么谢谢你
在 try catch 块之前添加一行
if (sk.GetValue("") != null)