用VB写一个可循环运行程序的代码??
来源:百度知道 编辑:UC知道 时间:2024/06/24 08:12:32
以下以 记事本 和 注册表编辑器 为例:
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_TERMINATE = 1
Private Sub Form_Load()
Timer1.Interval = 15000
End Sub
Private Sub Timer1_Timer()
Static b As Boolean, pid As Integer
Dim lProcess As Long
lProcess = OpenProcess(PROCESS_TERMINATE, False, pid)
TerminateProcess lProcess, 1
CloseHandle lProcess
b = Not b
pid = Shell(IIf(b, "notepad", "regedit"), vbNormalFocus)
End Sub
timer+shell
Private Sub Form_Load()
Timer1.Interval = 15000
End S