我可以在某些进程开始时收到通知吗? [英] Can I Get Notified When Some Process Starts?

查看:41
本文介绍了我可以在某些进程开始时收到通知吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

foo.exe 启动时,我需要知道(最好是延迟最少).

I need to know (preferably with the least latency) when foo.exe is launched.

现在,我有一个线程位于一个轻循环(~10 Hz)中,并在进程树中查找 foo.exe.

Right now, I have a thread that sits in a light loop (~10 Hz) and walks the process tree looking foo.exe.

这不太优雅,我想知道是否可以注册 Windows API 的某些部分以在任何进程启动时获得回调.

This is less than elegant and I was wondering whether I could register with some part of the Windows API to get a callback when any process starts.

如果没有这样的工具,我当然愿意接受其他更优雅地完成这项任务的方法.

If no such facility is available, I am, of course, open to other methods of accomplishing this task more elegantly.

推荐答案

您可以通过 图像文件执行选项.每当系统需要启动 foo.exe 时,它​​都会启动您的应用程序并将 foo.exe 及其参数传递给您.您必须自己开始这个过程.

You can register yourself as a debugger for foo.exe through the Image File Execution Options. Anytime the system needs to launch foo.exe, it'll launch your app and pass foo.exe and its parameters to you. You will have to start the process yourself.

注意:像往常一样,一些注意事项 Raymond Chen.

Note: as usual, some words of caution by Raymond Chen.

您还可以设置系统范围的消息挂钩 并且对于你的 dll 被加载的每个新进程,检查它是否是你关心的那个你只是通过,对于 foo.exe 你通知自己然后通过.不幸的是,这意味着您将在每个进程中注入您的代码,并且您将稍微损害系统性能.更不用说,如果您的代码中存在错误,您实际上可以对每个人进行灌输.

You can also set a system-wide message hook and for each new process your dll gets loaded, check if it's the one you care you just pass through, for foo.exe you notify yourself and then pass through. Unfortunately, that means you will be injecting your code in each process and you will be hurting the system perf a little bit. Not to mention that you can actually hose everybody if you have a bug in your code.

这篇关于我可以在某些进程开始时收到通知吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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