怎样用进程关闭程序?
示例一:
以下是使用Process结束进程:
dim pcs() AS Process
pcs= Process.GetProcessesByName("iExplore");
Dim i as integer
For i=0 to pcs.Length-1
pcs(i).Kill
Next
示例二:
dim pcs() as Process
’不知道为什么不行了??改用GetProcesses
’pcs=Process.GetProcessesByName("TM")
pcs=Process.GetProcesses()
dim i as Integer=0
for i=0 To pcs.GetUpperBound(0)-1
If pcs(i).ProcessName.ToUpper="TM".ToUpper Then pcs(i).Kill()
Next
示例三:
Private Sub KillProcess(byval processName as String)
Dim myproc as System.Diagnostics.Process = new System.Diagnostics.Process()
//得到所有打开的进程
Try
For Each thisproc as Process in Process.GetProcessesByName(processName)
If(Not thisproc.CloseMainWindow())
thisproc.Kill()
End If
Next
catch(Exc as Exception)
msgbox "杀死 " + processName + " 失败!"
End Try
End Sub
顺便说一下这段代码要在WinApp下才有效!