我已得出当前正在运行的进程在此基础上的代码如何查找运行已安装的软件名称和版本处理
static void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
uint pid;
GetWindowThreadProcessId(hwnd, out pid);
foreach (Process p in Process.GetProcesses())
{
if (p.Id == pid)
new TrayLog().Log(
System.Security.Principal.WindowsIdentity.GetCurrent().Name + "^" + p.Id + "^" + p.ProcessName + "^" + System.DateTime.Now.ToString("yyyyMMddHHmmss")
);
}
}
而且当前已安装的软件列表中的列表是基于下面的代码推导 RegistryKey键;
// search in: CurrentUser
key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
foreach (String keyName in key.GetSubKeyNames())
{
RegistryKey subkey = key.OpenSubKey(keyName);
try
{
if (!subkey.GetValue("DisplayName").Equals(null))
{
DataRow rows = dts.NewRow();
rows["Machine_UUID"] = Machine_UUID;
rows["Display_Name"] = subkey.GetValue("DisplayName").ToString();
rows["Display_Version"] = subkey.GetValue("DisplayVersion").ToString();
rows["Internal_Version"] = subkey.GetValue("Version").ToString();
rows["Installation_Date"] = DateTime.ParseExact(subkey.GetValue("InstallDate").ToString(), "yyyyMMdd", null);
rows["strInstallation_Date"] = ((DateTime)rows["Installation_Date"]).ToString("yyyyMMdd");
rows["Installation_Location"] = subkey.GetValue("InstallLocation").ToString();
rows["Installation_Source"] = subkey.GetValue("InstallSource").ToString();
rows["Uninstall_String"] = subkey.GetValue("UninstallString").ToString();
rows["Estimated_Size"] = subkey.GetValue("EstimatedSize").ToString();
dts.Rows.Add(rows);
}
}
catch (Exception e) { }
}
我需要匹配这两个列表,这样我需要的软件名称和运行过程中的其他细节...
并非所有正在运行的进程都将具有相应的卸载条目。 –