问题描述:
我枣简想要编一个监控进程(比如iexplore.exe)这个进程,每秒钟检测一次,发现这个进程马上结束掉这个进程,请问各位,这个代码应该怎么编写。
解析:
这个问题可以这样的解决:vb6下编译通过的。
Private Const PROCESS_TERMINATE = &H1
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Timer1_Timer()
Dim hProcess As Long
hProcess = Shell("notepad.exe", vbNormalFocus) '取得id
Sleep (1000)
hProcess = OpenProcess(PROCESS_TERMINATE, 0&, hProcess) '取得句柄
TerminateProcess hProcess, 0&'结束进程
Timer1.Enabled = False
CloseHandle hProcess
End Sub
注意:timer1的interval的属性设置为1000,
:notepad.exe是随便写的,你可以改成你要的监控进程.
:所有的vb的api函数都在vb6的猜搭apiview工具之中可以得到!
用"End"强制程序结束运行,给出一段旦昌返程序:Private Sub Command1_Click()
Dim a As Integer,b As Integer
a=Val(Text1.Text)
b=Val(Text2.Text)
Text3.Text=a+b
End Sub
在迅袜这段VB程序中,VB一直执行语句,直到最后一句结束语句”End Sub“,才结束程序运模饥行。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)