如何在windows中监控进程/程序的执行?
我们正在尝试开发一个小型应用程序,可以监视 Windows 计算机中正在执行的程序/进程。
如果程序/进程不应该运行,则应将其阻止。 它的工作原理类似于防病毒软件。
这是基本思想。
我想知道如何连接操作系统以获取有关尝试在计算机中运行的每个程序/进程的通知。
We are trying to develop a small application that can monitor the programs/processes that are executing in a windows machine.
If the program/process is not supposed to run, it should be blocked. It works similar to an antivirus.
This is the basic idea.
I want to know the ways to hook into the OS to get notified about every single program/process trying to run in the machine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最简单的方法是使用 WMI。 特别监视Win32_ProcessStartTrace。 这比 Win32_Process 更好,因为它被设置为使用事件,而 Win32_Process 需要轮询,这对 CPU 更密集。 下面是如何在 C# 中执行此操作。 首先确保 System.Management 已设置为您的项目的参考。
每次启动新进程时,代码都会生成一个消息框。 从那里您可以检查白名单/黑名单并采取适当的行动。
The easiest way is to use WMI. Specifically monitor the Win32_ProcessStartTrace. This is better than Win32_Process, because it is setup to use events whereas Win32_Process requires polling which is more CPU intensive. Below is how to do it in C#. First make sure that System.Management is setup as a reference for your project.
The code will generate a messagebox everytime you launch a new process. From there you can check a whitelist/blacklist and act appropriately.
我还没有尝试过获取实时通知。 然而,以下是如何在 C# 中获取正在运行的进程
您还可以使用进程的以下属性
I havn't tried geting real-time notification. How ever, Here is how to get running processes in C#
You can also use the following props of a process
我会使用常量 WH_GETMESSAGE 检查 Win32-api SetWindowsHookEx ,以便在创建新窗口时向程序添加回调。
http://pinvoke.net/default.aspx/user32.SetWindowsHookEx
Google 该 API和 WH_GETMESSAGE 了解更多信息。
另请查看以下文章/代码库:
http://www.vbaccelerator.com/home/ Vb/Code/Libraries/Hooks/vbAccelerator_Hook_Library/article.asp
http://www.codeproject.com/KB/DLL/hooks.aspx?fid=2061& ;df=90&mpp=25&噪音=3&sort=位置&view=Quick&fr=76&select=726975
I would check up the Win32-api SetWindowsHookEx with the constant WH_GETMESSAGE to add a callback to your program when a new window is being created.
http://pinvoke.net/default.aspx/user32.SetWindowsHookEx
Google that API and WH_GETMESSAGE to find out more.
Also check out the following articles/code librarys:
http://www.vbaccelerator.com/home/Vb/Code/Libraries/Hooks/vbAccelerator_Hook_Library/article.asp
http://www.codeproject.com/KB/DLL/hooks.aspx?fid=2061&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=76&select=726975