资源简介
通过读取注册表获取系统所有安装的软件信息,获取到的信息和系统程序和功能中一致
代码片段和文件信息
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text;
namespace SystemInfosLib
{
public class SoftWareList
{
///
/// 获取安装的所有程序
///
public virtual List GetAllInstalledSoftware()
{
List list = new List();
//添加32位程序
RegistryKey pregkey = Registry.LocalMachine.OpenSubKey(@“Software\Microsoft\Windows\CurrentVersion\Uninstall“);//获取指定路径下的键
AddSoftListRange(list pregkey);
//添加64位程序
pregkey = Get64BitOsKey();
AddSoftListRange(list pregkey);
//当前用户
pregkey = Registry.CurrentUser.OpenSubKey(@“Software\Microsoft\Windows\CurrentVersion\Uninstall“);
AddSoftListRange(list pregkey);
return list;
}
///
/// 获取正在运行的程序
///
///
public virtual List GetRunningSoftList()
{
ProcessInfos soft;
List listRunning = new List();
ServiceController[] services = System.ServiceProcess.ServiceController.GetServices();
for (int i = 0; i < services.Length; i++)
{
String state = ““;
if ((services[i].Status.ToString()).Equals(“Running“))
{
state = “正在运行“;
soft = new ProcessInfos(services[i].ServiceName services[i].DisplayName state);
listRunning.Add(soft);
}
}
return listRunning;
}
private RegistryKey Get64BitOsKey()
{
RegistryKey pregkey = null;
try
{
RegistryKey localKey;
localKey = RegistryKey.OpenbaseKey(RegistryHive.LocalMachine RegistryView.Registry64);
pregkey = localKey.OpenSubKey(@“Software\Microsoft\Windows\CurrentVersion\Uninstall“);//获取指定路径下的键
}
catch (Exception ex)
{
}
return pregkey;
}
private List GetSoftKeyFromReg(RegistryKey pregkey)
{
List list = new List();
string temp = null tempType = null;
int softNum = 0;
RegistryKey currentKey = null;
try
{
foreach (string item in pregkey.GetSubKeyNames()) //循环所有子键
{
string displayName uninstallString releaseType PublishName oInstallTime oSize oVersion;
currentKey = pregkey.OpenSubKey(item);
displayName = currentKey.GetValue(
- 上一篇:Asp.net 基础教程含视频+进阶视频
- 下一篇:c#对文件加密
评论
共有 条评论