进程名称中的应用程序名称 [英] application name from process name

查看:193
本文介绍了进程名称中的应用程序名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii ..
每当用户运行任何应用程序时,我都想让事件获取应用程序名称.
到目前为止,我已经从
找到了 医学博士.拉希姆·乌丁(Rashim uddin)

Hii..
I want to make and event to get the application name whenever user runs any application.
so far i''ve found this from
Md. Rashim uddin

public partial class Form1 : Form
    {
        public System.Management.ManagementEventWatcher mgmtWtch;
 
        public Form1()
        {
            InitializeComponent();
            mgmtWtch = new System.Management.ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
            mgmtWtch.EventArrived += new System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
            mgmtWtch.Start();
        }
 
        private void mgmtWtch_EventArrived(object sender, System.Management.EventArrivedEventArgs e)
        {
            MessageBox.Show((string)e.NewEvent["ProcessName"]);
        }       
    }



这获得了进程名称,但我想要应用程序名称...
是否有任何方法可以从进程名称中获取该信息.



this get the process name but i want the application name...
is there is any way to get that from process name..

thanks for your time.

推荐答案

这是一个解决您问题的C ++项目:
检测Windows NT/2K进程执行 [ DllImportAttribute [^ ],以从c#
访问所需的本机函数
[更新]
Here is a C++ project that solves your problem:
Detecting Windows NT/2K process execution[^]

You can either create a C++/CLI project based on the code, or use the DllImportAttribute[^] to access the required native functions from c#

[Update]
#include <cstdio>
#include <windows.h> 
#include <tlhelp32.h> 
 
int main( int, char *[] ) 
{ 
 PROCESSENTRY32 entry; 
 entry.dwSize = sizeof(PROCESSENTRY32); 
 
 HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL); 
 
 if (Process32First(snapshot, &entry) == TRUE) 
 { 
  while (Process32Next(snapshot, &entry) == TRUE) 
  {
   char buffer[512] = {0,};
   DWORD bufferSize = sizeof(buffer) - 1;
   HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID); 
 
   QueryFullProcessImageName(hProcess,PROCESS_NAME_NATIVE,buffer,&bufferSize);
 
   CloseHandle(hProcess); 
  } 
 } 
 
 CloseHandle(snapshot); 
 
 return 0; 
} 


PROCESSENTRY32结构的szExeFile成员并不总是包含完整路径.

所有功能都记录在MSDN 进程和线程函数 [ ^ ]

工具帮助功能 [ PsSetCreateProcessNotifyRoutine [


The szExeFile member of the PROCESSENTRY32 structure does not always contain the full path.

All of the functions are documented in MSDN Process and Thread Functions[^]

Tool Help Functions[^]

PsSetCreateProcessNotifyRoutine[^] is exported from NTOSKRNL and only available to drivers - the article refered to above explains how you can get a notification from your driver to a user process whenever a process is started.

Obviously it''s easier to follow Mikas example - just use a timer and execute it every 10 seconds or so.

Best regards
Espen Harlinn


这就是您遇到此问题的原因:对于任意Windows应用程序,没有应用程序名称"之类的概念.你不能学到不存在的东西.

实际上,它的.NET程序集具有一些常用的属性,例如程序集名称和产品名称,但没有一个被称为应用程序名称".组装和应用是不同的东西.要查找装配体属性,您应该加载一个并使用反射.问题是:只有某些进程是.NET应用程序.

正如Mika已经解释的那样,还有一个主应用程序窗口标题.它可能存在也可能不存在,并且-再次引起麻烦-这不是应用程序名称".不,你不能学到不存在的东西.

—SA
Here is why you have this problem: for an arbitrary Windows application, there is no such concept as "Application name". You cannot learn something which does not exist.

Actually, it''s .NET assembly that has some typically used attributes such as assembly name and product name, but none of them is called "application name". Assembly and application are different things. To find assembly attributes, you should load one and use Reflection. The problem is: only some of the processes are .NET applications.

As Mika already explained, there is also a main application window title. It may or may not exist and — trouble again — this is not "application name". No, you cannot learn something which does not exist.

—SA


使用应用程序名称,您的意思是窗口的主标题.如果是这样,并且您已经知道该过程,则可以使用过程.MainWindowTitle属性 [ ^ ].

如果仅知道进程ID,则可以使用 Process.GetProcessById方法 [
With application name, do you mean the main title of a window. If that''s the case and yo ualready know the process, you can use Process.MainWindowTitle Property[^].

If you know only the process id you can use Process.GetProcessById Method[^] to resolve the Process object.


这篇关于进程名称中的应用程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆