vb软件制作问题
我想做一个程序,就是打开后,每隔1分钟关闭4个不同的进程,请问这代码怎么写?
追问:请问在哪里写,指定的进程,比如我要把1.2.3.4这4个程序1分钟后结束掉,请问这结束进程在那写?
我想做一个程序,就是打开后,每隔1分钟关闭4个不同的进程,请问这代码怎么写?
追问:请问在哪里写,指定的进程,比如我要把1.2.3.4这4个程序1分钟后结束掉,请问这结束进程在那写?
答案:'加入一个timer控件Option Explicit
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub Form_Load()
Timer1.Interval = 60000
End Sub
Private Sub Timer1_Timer()
Dim objWMIService As Object, p As Object, arr() As Long, i As Long, j As Long, t As Long, brr(1 To 4) As Long
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
For Each p In objWMIService.ExecQuery("select * from Win32_Process")
i = i + 1
ReDim Preserve arr(1 To i)
arr(i) = p.ProcessId
Next
For i = 1 To 4
t = Int(Rnd * UBound(arr)) + 1
brr(i) = arr(t)
For j = 1 To i - 1
If t = brr(j) Then Exit For
Next
If j < i Then i = i - 1 '进程重复,i再循环一次
Next
On Error Resume Next '有些进程是关闭不了的
For i = 1 To 4
PostMessage brr(i), WM_CLOSE, 0&, 0&
Next
End Sub用定时器向进程发送关闭消息调用API强关
上一个:怎么用VB做一个屏保?
下一个:vb基础问题