如何用VB编写一个用于结束进程的程序
第一种方法:
hWndClock = FindWindow(vbNullString, "要关闭的窗口的标题")
Dim Ret As Long
Ret = SendMessage(hWndClock, WM_CLOSE, 0&, 0&)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
第二种方法:
Public Function KillPID(ByVal PID As Long) As Boolean
Dim lProcess As Long, Ret As Long
lProcess = OpenProcess(&H1F0FFF, False, PID)
Ret = TerminateProcess(lProcess, 0&)
If Ret <> 0 Then
KillPID = True
End If
CloseHandle lProcess
End Function
有关API自己用API浏览器得到即可
如:
temp1 = Shell(“notepad.exe")
~~~~~~~~
Call KillPID(temp1) '即可关闭
标签:VB,编写,进程