Public?Sub?KillProcessFromMemorry()
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),軹城企業(yè)網(wǎng)站建設(shè),軹城品牌網(wǎng)站建設(shè),網(wǎng)站定制,軹城網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,軹城網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強企業(yè)競爭力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
'注意進程名稱的大小寫
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)操作時加排錯標(biāo)簽是個好習(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: ‘定義排錯標(biāo)簽
If Err.Description Nothing Then ’判斷有無錯誤,如果有,則 ↓
MsgBox(Err.Description) '當(dāng)出現(xiàn)錯誤時,彈窗提示
End If
End Sub
可根據(jù)需要自行修改,這個備注夠完善了吧?不會的再Hi我。
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
軟糖來回答羅:通過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
下面是具體結(jié)束所有Excel進程的代碼
Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
Dim?p?As?Process()?=?Process.GetProcessesByName("EXCEL")
For?Each?pr?As?Process?In?p
pr.Kill()
Next
End?Sub