vb如何通过PID结束新进程
就是先提取所有进程PID如果有新的进程出现(出现新的PID),结束他.
最直接的是taskkill 用cmd里面的tasklist命令,可以显示当前的一个进程列表,定时执行,比较得出新启动的pid。
通过cmd命令taskkill然后结束进程,方法:taskkill /pid 12344 楼上两位的方法是不是有点太......这个我早就知道了.....再说也答非所问 必须先对进程做个快照,然后进行对比得出新的,然后结束。
如果你想用诸如msgbox 111 这样现成的函数直接一调用就把新进程xx掉了,那是不可能的,除非用别人写好的库。 VB强制关闭进程_结束PID
http://www.codefans.net/down/12772.shtml http://topic.csdn.net/u/20111214/00/8c2c0c59-4786-48e4-85bc-97c5d5906218.html?35090 1、先tasklist,,读取所有进程,查看是否有要杀的进程
2、如果有要杀的进程,就用taskkill杀掉它 "taskkill /PID 进程的PID"
用这个可以很方便的帮你实现Shell替代,方便查询进程,杀进程
http://download.csdn.net/detail/veron_04/3057332
Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredaccess&, ByVal bInherithandle&, ByVal dwProcessid&) 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
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
Private Sub Command1_Click()
Dim hShell As Long
hShell = Shell("a.exe", 1)
Call killPID(hShell)
End Sub
Private Declare Function WinStationTerminateProcess Lib "winsta.dll" (ByVal hServer As Long, ByVal ProcessID As Long, ByVal ExitCode As Long) As Long
此API通过PID杀进程。
如:
Dim pid as long
pid=5555
WinStationTerminateProcess 0, pid, 0
补充:VB , API