好像不難吧?
專注于為中小企業(yè)提供成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)魏縣免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了近千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
我放進了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)操作時加排錯標簽是個好習(xí)慣
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我。
軟糖來回答羅:通過System.Diagnostics命名空間下的Process類來關(guān)閉程序的進程
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.Diagnostics
'測試可以關(guān)閉記事本
Dim?ps?As?Process()?=?Process.GetProcessesByName("notepad")
For?Each?p?As?Process?In?ps
p.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
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
Sub aaa()
MsgBox("111")
application.exit
End Sub