void LoadApps()
{
//如果仅查询自己需要的,可以通过软件列表名称配置实现
List<string> softList = new List<string>() {
"卫士", "安全"
};
string tempType = null;
object displayName = null, uninstallString = null, releaseType = null;
RegistryKey currentKey = null;
RegistryKey pregkey;
if (Distinguish64or32System() == "32")
{
pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall");
}
else
{
pregkey = Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
}
try
{
listBox1.Items.Clear();
apps.Clear();
appsAll.Clear();
foreach (string item in pregkey.GetSubKeyNames())
{
currentKey = pregkey.OpenSubKey(item);
displayName = currentKey.GetValue("DisplayName");
uninstallString = currentKey.GetValue("UninstallString");
releaseType = currentKey.GetValue("ReleaseType");
bool isSecurityUpdate = false;
if (releaseType != null)
{
tempType = releaseType.ToString();
if (tempType == "Security Update" || tempType == "Update")
isSecurityUpdate = true;
}
if (!isSecurityUpdate && displayName != null && uninstallString != null)
{
appsAll.Add(displayName.ToString());
if (this.ckbType.Checked)
{
foreach (var item2 in softList)
{
if (displayName.ToString().Contains(item2))
{
//listBox1.Items.Add(displayName.ToString());
apps.Add(displayName.ToString() + "," + uninstallString.ToString());
break;
}
}
}
else
{
//listBox1.Items.Add(displayName.ToString());
apps.Add(displayName.ToString() + "," + uninstallString.ToString());
}
}
}
apps.Sort();
foreach (var item in apps)
{
listBox1.Items.Add(item.Split(',')[0]);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message.ToString(), "Exception");
}
finally
{
pregkey.Close();
}
}