在机器异常之后重新执行程序
Re-execute a program after machine exception
我有一个预编译EXE(本机C 11),该EXE在迭代过程的某个时候崩溃(访问违规错误)。我现在无法负担调试并暂时重新编译。
我想到了一个肮脏的解决方案。我将制作另一个负责执行该EXE的程序,当它停止工作时,我只是再次重新执行它。
有可能吗?我怎么知道该程序已停止?
注意:我在Windows上并使用MSV进行开发。
我在@richard Hodges的帮助下找到了解决方案。
使用此代码制作新程序:
#include <Windows.h>
#include <string>
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
int main(int argc, const char**argv) {
while (true) {
TCHAR ProcessName[256];
STARTUPINFO si;
PROCESS_INFORMATION pi;
wcscpy(ProcessName, L"FaultyProgram.exe");
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory(&pi, sizeof(pi));
// Start the child process.
if (!CreateProcess(NULL, // No module name (use command line)
ProcessName, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
CREATE_NEW_CONSOLE, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&si, // Pointer to STARTUPINFO structure
&pi) // Pointer to PROCESS_INFORMATION structure
)
{
printf("CreateProcess failed (%d).n", GetLastError());
return 0;
}
// Wait until child process exits.
WaitForSingleObject(pi.hProcess, INFINITE);
// Close process and thread handles.
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
return 0;
}
,最重要的部分是当程序通过在注册表中更改此值崩溃时禁用UI错误消息:
HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsWindows Error Reporting
"DontShowUI"=dword:00000001
而不是:
"DontShowUI"=dword:00000000
相关文章:
- 程序在执行程序的其余部分之前退出
- libprotobuf 检查在 Mac OS 上执行程序时失败
- 是否可以依赖函数范围的静态变量来执行程序关闭期间调用的方法?
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 从 GUI 文件资源管理器执行程序,并且不生成终端
- 测试操作系统时执行程序集"sti"时虚拟框崩溃
- 重新执行C++程序会加快速度
- 如何用共享库替换可执行C++程序的功能?
- 编译并执行C#程序中的C++代码
- 如果我在 Linux 上更改C++动态共享库,而我的可执行程序在其上使用,会发生什么
- 在C++中,系统如何将这些对象中的每一个与执行程序的窗口相关联?
- 命令行参数执行C 程序
- 执行QACTION之后如何设置焦点
- 按 e 执行程序C++
- 在返回另一个函数的函数中执行程序期间出错
- 如何使用"trusty"映像在本地执行C++程序的Travis CI?
- 当我们说在执行程序时将操作系统的控制权传递给main()函数时,我们的意思是什么
- execve(..) 不执行程序,尽管传入了 PATH 变量
- 在机器异常之后重新执行程序
- 调试和发布库及其可执行程序