如何在Windows中挂钩应用程序和进程启动?
发布时间:2020-05-22 12:33:33 所属栏目:Windows 来源:互联网
导读:我正在尝试编写一个程序,它将挂钩到应用程序启动并捕获命令行.不知道从哪里开始,因为我在 Windows编程中非常环保. 非常感谢任何帮助 谢谢 你没有提到你喜欢的编程语言,所以我将使用C#作为代码片段. 您可以启动进程并捕获/写入其标准IO流. 以下代码段打开一个
|
我正在尝试编写一个程序,它将挂钩到应用程序启动并捕获命令行.不知道从哪里开始,因为我在
Windows编程中非常环保.
您可以启动进程并捕获/写入其标准IO流. 以下代码段打开一个进程并捕获其StdOut流: using (var process = Process.Start(new ProcessStartInfo(FileName = @"yourExecutablePath",UseShellExecute = false,RedirectStandardOutput = true)))
using (var stdout = process.StandardOutput)
Console.WriteLine(stdout.ReadToEnd());
编辑1 看起来你想挂钩像CreateProcess这样的Windows API. 一种方法是编写内核驱动程序并使用诸如SSTD修补之类的挂钩技术.但编写内核驱动程序IMO非常麻烦. 在某些情况下,您可以使用用户级挂钩.有一些图书馆可以帮助您,包括:EasyHook,Deviare和MS Detour. 编辑2 您也可以使用WMI作为 using System.Management;
// Run this in another thread and make sure the event watcher gets disposed before exit
var start = new ManagementEventWatcher(new WqlEventQuery("SELECT * FROM Win32_ProcessStartTrace"));
start.EventArrived += new EventArrivedEventHandler(delegate (object sender,EventArrivedEventArgs e) {
console.WriteLine("Name: {0},Command Line: {1}",e.NewEvent.Properties["ProcessName"].Value,e.NewEvent.Properties["Commandline"].Value);
});
start.Start() (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- DLL符号_FooBar @ 16中的数字16代表什么?
- FFMPEG在Windows下的屏幕录像录音
- windows – 如何从命令行启动一个ruby脚本只是它的名字?
- Shared Event-loop for Same-Origin Windows(译)
- Win2012 R2 Boot Configuration Data is missing
- Windows中为Latex添加.sty文件
- Windows Apache2.2.11及Php5.2.9-1的安装与配置方法
- office365 – 使用Microsoft Graph API显示即将到来的Offic
- winapi – 来自Win32应用程序的x64图像上的OpenProcess
- windows – 为cmd启用颜色输出
