軟糖來回答羅:通過System.Diagnostics命名空間下的Process類來關(guān)閉程序的進程
成都創(chuàng)新互聯(lián)是一家專注于網(wǎng)站設計制作、網(wǎng)站建設與策劃設計,團風網(wǎng)站建設哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十多年,網(wǎng)設計領域的專業(yè)建站公司;建站業(yè)務涵蓋:團風等地區(qū)。團風做網(wǎng)站價格咨詢:13518219792
Dim?進程集合?=?Process.GetProcessesByName("進程名稱")
For?Each?進程?In?進程集合
進程.Kill()
'進程.Close()?'或者使用關(guān)閉
Next
也可以先獲取所有進程,再來判斷這些進程的名稱ProcessName
Dim?獲取本地所有進程?=?Process.GetProcesses()
For?Each?進程?In?獲取本地所有進程
If?進程.ProcessName?=?"explorer.exe"?Then?進程.Kill()
Next
Imports System
Imports System.Management
Module Module1
Public Sub Main()
Dim service As ManagementObject = New ManagementObject( "win32_service=""winmgmt""")
Dim options As InvokeMethodOptions = New InvokeMethodOptions
options.Timeout = New TimeSpan(0, 0, 0 , 5)
Dim outParams As ManagementBaseObject = service.InvokeMethod("StopService" , Nothing, options)
Console.WriteLine("狀態(tài):" outParams("Returnvalue"))
End Sub
End Module
Sub aaa()
MsgBox("111")
application.exit
End Sub
Public?Sub?KillProcessFromMemorry()
'注意進程名稱的大小寫
Dim?procName?As?String?=?"EXCEL"
For?Each?proc?In?Process.GetProcesses
If?proc.ProcessName?Like?procName?Then
Console.WriteLine("'{0}'?is?running,?do?you?want?to?quit?(y,?n)",?procName)
If?Console.ReadKey.Key?=?ConsoleKey.Y?Then
proc.Kill()
End?If
End?If
Next
End?Sub
好像不難吧?
我放進了Button1的Click事件里。
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
On Error GoTo Errmessages '在做系統(tǒng)操作時加排錯標簽是個好習慣
Dim TargetName As String = "ibmdict" '存儲進程名為文本型,注:進程名不加擴展名
Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '從進程名獲取進程
Dim TargetPath As String '存儲進程路徑為文本型
If TargetKill.Length 1 Then '判斷進程名的數(shù)量,如果同名進程數(shù)量在2個以上,用For循環(huán)關(guān)閉進程。
For i = 0 To TargetKill.Length - 1
TargetPath = TargetKill(i).MainModule.FileName
TargetKill(i).Kill()
Next
ElseIf TargetKill.Length = 0 Then '判斷進程名的數(shù)量,沒有發(fā)現(xiàn)進程直接彈窗。不需要的,可直接刪掉該If子句
MsgBox("沒有發(fā)現(xiàn)進程!")
Exit Sub
ElseIf TargetKill.Length = 1 Then '判斷進程名的數(shù)量,如果只有一個,就不用For循環(huán)
TargetKill(0).Kill()
End If
MsgBox("已終止" TargetKill.Length "個進程") '彈窗提示已終止多少個進程
Errmessages: ‘定義排錯標簽
If Err.Description Nothing Then ’判斷有無錯誤,如果有,則 ↓
MsgBox(Err.Description) '當出現(xiàn)錯誤時,彈窗提示
End If
End Sub
可根據(jù)需要自行修改,這個備注夠完善了吧?不會的再Hi我。