我知道如何使用ADPlus或DebugDiag生成Crash Dump文件,但我想知道是否有办法在客户的计算机上执行此操作而不安装这些工具...具体来说,我希望能够配置我的应用程序(例如,使用注册表值)在严重故障的情况下生成崩溃转储。更具体地说,我需要能够从C#应用程序执行此操作,但如果有必要,我不介意P / Invoke。谢谢!
发布于 2019-04-16 08:08:06
我想如果你的应用程序被软管,那么你可能会尝试创建一个迷你转储文件,这将是最糟糕的,你的应用程序将崩溃?无论如何它正在这样做,所以你不妨试试。VoiDed提到 的MSDN论坛中的代码看起来非常可靠。我需要一个VB.Net版本所以这里是一个VB版本,适合任何可能需要它的人:
Friend Class MiniDump
'Code converted from C# code found here: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/6c8d3529-a493-49b9-93d7-07a3a2d715dc
Private Enum MINIDUMP_TYPE
MiniDumpNormal = 0
MiniDumpWithDataSegs = 1
MiniDumpWithFullMemory = 2
MiniDumpWithHandleData = 4
MiniDumpFilterMemory = 8
MiniDumpScanMemory = 10
MiniDumpWithUnloadedModules = 20
MiniDumpWithIndirectlyReferencedMemory = 40
MiniDumpFilterModulePaths = 80
MiniDumpWithProcessThreadData = 100
MiniDumpWithPrivateReadWriteMemory = 200
MiniDumpWithoutOptionalData = 400
MiniDumpWithFullMemoryInfo = 800
MiniDumpWithThreadInfo = 1000
MiniDumpWithCodeSegs = 2000
End Enum
<Runtime.InteropServices.DllImport("dbghelp.dll")> _
Private Shared Function MiniDumpWriteDump( _
ByVal hProcess As IntPtr, _
ByVal ProcessId As Int32, _
ByVal hFile As IntPtr, _
ByVal DumpType As MINIDUMP_TYPE, _
ByVal ExceptionParam As IntPtr, _
ByVal UserStreamParam As IntPtr, _
ByVal CallackParam As IntPtr) As Boolean
End Function
Friend Shared Sub MiniDumpToFile(ByVal fileToDump As String)
Dim fsToDump As IO.FileStream = Nothing
If (IO.File.Exists(fileToDump)) Then
fsToDump = IO.File.Open(fileToDump, IO.FileMode.Append)
Else
fsToDump = IO.File.Create(fileToDump)
End If
Dim thisProcess As Process = Process.GetCurrentProcess()
MiniDumpWriteDump(thisProcess.Handle, _
thisProcess.Id, _
fsToDump.SafeFileHandle.DangerousGetHandle(), _
MINIDUMP_TYPE.MiniDumpNormal, _
IntPtr.Zero, _
IntPtr.Zero, _
IntPtr.Zero)
fsToDump.Close()
End Sub
End Class
只要确保你能够完全处理对它的调用,你应该相对安全。
发布于 2019-04-16 09:05:01
您可以使用以下注册表脚本配置Windows错误报告(WER)以在特定目录中创建故障转储:
Windows注册表编辑器版本5.00
[HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ Windows错误报告\ LocalDumps]
“DumpFolder”= “C:\\转储”
“DumpCount”= DWORD:00000064
“DumpType”= DWORD:00000002
“CustomDumpFlags”= DWORD:00000000
转储将进入C:\ Dumps,其名称反映崩溃进程的名称。DumpType = 2给出完整的内存转储。DumpType = 1给出了一个小型转储。在64位计算机上,您不需要将它们放在Wow32节点下。WER仅使用上面指定的非WOW注册表项。
根据崩溃的类型,此方法可能无效。我还没弄清楚为什么或哪些碰撞类型没有捕获。
https://stackoverflow.com/questions/-100001110
复制相似问题