在 vb6 中监视进程以查看它们是否崩溃
我有一个程序在我睡觉时经常崩溃,但我需要保持它运行。 所以我想我可以写一个vb6应用程序来监视进程列表,如果有东西消失它会重新启动它。 有人知道一个简单的方法吗?
I've got a program that tends to crash quite often while I'm asleep and I need to keep it running. So I thought I might writeup a vb6 application that monitors the process list, if something disappears it will relaunch it. Anyone know of an easy way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用了计划任务(每 10 分钟运行一次),用下一个内容启动 cmd 文件:
您可以从 VB6 Shell 执行此类命令文件或仅使用任务计划程序:)
I've used scheduled task (running at each 10 min), starting cmd file with next content:
You can execute such command file from VB6 Shell or just use Task Scheduler :)
您可以使用 EnumProcesses 列出中的每个进程在您正在运行的系统中,您可以使用此声明来使用它。
在使用它之前,您应该定义一个 Long 数组作为参数传递给 EnumProcesses,并有足够的空间来读取所有进程 ID。 您可以调用 EnumProcesses 两次来了解该数组应该有多大。
在第二次调用之后,您可以开始循环遍历该数组并打开进程,以这种方式获取适当使用的句柄可以告诉您进程可执行文件的名称,并将该数据与您正在搜索的可执行文件的名称进行比较,您就完成了。 否则,如果您要查找的是 DLL,例如,您可以使用该进程句柄的 EnumProcessModules 搜索您要查找的 dll 的每个正在运行的进程。
EnumProcessModules 的声明是这样的
,您需要的可能代码是这样的:这个
函数代码有点长,但调用它是一个小函数,如果您想稍微测试一下,您可以使用它:)
You could use EnumProcesses to list every process in the system at the moment you're running you could use this declaration to use it
Prior using it you should define an array of Long to pass as an argument to EnumProcesses with enough space to read all processes ids. You could call EnumProcesses twice to discover how large that array should be.
After the second call you could start looping through that array and opening the processes obtaining that way a handle which used appropriately can tell you the name of the process executable and comparing that data with the name of the executable you're searching you are done. Otherwise if what you're looking for is a DLL for example you could EnumProcessModules for that process handle searching for each running process for the dll you're looking for.
the declaration of EnumProcessModules is this
and the probable code you'd need would be something like this
function code is a little long but calling it is a little function, you may use it if you want to test it a little :)
使用WMI。
如果您无法使用 VB6,请在网上搜索 WMI+VB6。
否则,连接 C# 和 WMI 会容易得多。
Use WMI.
If you're stuck with VB6, search the web for WMI+VB6.
Otherwise, interfacing c# and WMI is much easier.
我使用一个运行其他程序的程序。 这样您就可以轮询进程句柄以查看应用程序是否仍在运行。 如果没有,您可以再次启动它。 它确实需要 API 编程。
I use a program that runs other programs. That way you can poll the process handle to see if the application is still running. If not you can launch it again. It does require API programming.