2016-07-20 50 views
0

我已得出当前正在运行的进程在此基础上的代码如何查找运行已安装的软件名称和版本处理

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) { } 
} 

我需要匹配这两个列表,这样我需要的软件名称和运行过程中的其他细节...

+0

并非所有正在运行的进程都将具有相应的卸载条目。 –

回答

0

你可以得到Process.MainModule.FileName,然后使用FileVersionInfo.FileDescription得到显示名称。

然后使用这个键,它是所有当前安装程序的列表及其卸载信息。

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall 

现在从键中获取显示名称并将它们与过程显示名称进行比较。

+0

谢谢shad0wk,Process.MainModule是我所期望的,但是从ProductName和ProductVersion检索的值与“HKEY_LOCAL_MACHINE \ SOFTWARE \ WOW6432Node \ Microsoft \ Windows \ CurrentVersion \ Uninstall”中的DisplayKey和DisplayKey的DisplayVersion不匹配。例如:ProductName:Microsoft®VisualStudio®2012 - ProductVersion:11.0.50727.1!= DisplayName:Microsoft Visual Studio 2012 Devenv,DisplayVersion:11.0.50727 –

+0

也许您可以获取文件名,删除扩展名并将其与RegistryKey DisplayName以及。它可能会得到一些比赛。 –

相关问题