C# 抓取进程快照 propDump方式

互联网 2022/6/29 7:25:17

private static void CreateMiniDump(string processName) { var pl = Process.GetProcessesByName(processName); if (pl.Length == 0) { Console.WriteLine($"找不到进程:{processName}"); …

private static void CreateMiniDump(string processName)
{
var pl = Process.GetProcessesByName(processName);
if (pl.Length == 0)
{
Console.WriteLine($"找不到进程:{processName}");
return;
}

var process = pl[0];
{
Process.Start("plugins\\procdump.exe", $"-ma {process.Id} -o {AppDomain.CurrentDomain.BaseDirectory}");

//MiniDumpWriteDump(process.Handle,
// process.Id,
// fs.SafeFileHandle.DangerousGetHandle(),
// MINIDUMP_TYPE.MiniDumpNormal,
// IntPtr.Zero,
// IntPtr.Zero,
// IntPtr.Zero);
Console.WriteLine("完成");
}
}

[DllImport("dbghelp.dll")]
public static extern bool MiniDumpWriteDump(IntPtr hProcess,
Int32 ProcessId,
IntPtr hFile,
int DumpType,
IntPtr ExceptionParam,
IntPtr UserStreamParam,
IntPtr CallackParam);

 

public static class MINIDUMP_TYPE
{
public const int MiniDumpNormal = 0x00000000;
public const int MiniDumpWithDataSegs = 0x00000001;
public const int MiniDumpWithFullMemory = 0x00000002;
public const int MiniDumpWithHandleData = 0x00000004;
public const int MiniDumpFilterMemory = 0x00000008;
public const int MiniDumpScanMemory = 0x00000010;
public const int MiniDumpWithUnloadedModules = 0x00000020;
public const int MiniDumpWithIndirectlyReferencedMemory = 0x00000040;
public const int MiniDumpFilterModulePaths = 0x00000080;
public const int MiniDumpWithProcessThreadData = 0x00000100;
public const int MiniDumpWithPrivateReadWriteMemory = 0x00000200;
public const int MiniDumpWithoutOptionalData = 0x00000400;
public const int MiniDumpWithFullMemoryInfo = 0x00000800;
public const int MiniDumpWithThreadInfo = 0x00001000;
public const int MiniDumpWithCodeSegs = 0x00002000;
}

 

static void Main(string[] args)
{


//https://docs.microsoft.com/en-us/sysinternals/downloads/procdump
//procdump -ma 4572

Console.WriteLine("正在生成内存快照,请稍等");
CreateMiniDump();

for (int i = 5; i > 0; i--)
{
Console.WriteLine($"完毕,{i}秒后退出...");
Thread.Sleep(1000);
}
}

随时随地学软件编程-关注百度小程序和微信小程序
关于找一找教程网

本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。
本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。
[C# 抓取进程快照 propDump方式]http://www.zyiz.net/tech/detail-331761.html

赞(0)
关注微信小程序
程序员编程王-随时随地学编程

扫描二维码或查找【程序员编程王】

可以随时随地学编程啦!

技术文章导航 更多>