Public?Sub?KillProcessFromMemorry()
彌勒網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)建站!從網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、成都響應(yīng)式網(wǎng)站建設(shè)等網(wǎng)站項(xiàng)目制作,到程序開發(fā),運(yùn)營維護(hù)。創(chuàng)新互聯(lián)建站2013年開創(chuàng)至今到現(xiàn)在10年的時(shí)間,我們擁有了豐富的建站經(jīng)驗(yàn)和運(yùn)維經(jīng)驗(yàn),來保證我們的工作的順利進(jìn)行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)建站。
槐棗????'注意進(jìn)程名稱的大小寫
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
好像不難吧?
我放進(jì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)操作時(shí)加排錯(cuò)標(biāo)簽是個(gè)好習(xí)慣
Dim TargetName As String = "ibmdict" '存儲(chǔ)進(jìn)程名為文本型,注:進(jìn)程名不加擴(kuò)展名
Dim TargetKill() As Process = Process.GetProcessesByName(TargetName) '從進(jìn)程名獲取進(jìn)程
Dim TargetPath As String '存儲(chǔ)進(jìn)程路徑為文本型
If TargetKill.Length 1 Then '判斷進(jìn)程名的數(shù)量,如果同名進(jìn)程數(shù)啟旁量在2個(gè)以上,用For循環(huán)關(guān)閉進(jìn)程。
For i = 0 To TargetKill.Length - 1
TargetPath = TargetKill(i).MainModule.FileName
TargetKill(i).Kill()
Next
ElseIf TargetKill.Length = 0 Then '判斷進(jìn)程名的數(shù)量,沒有發(fā)現(xiàn)進(jìn)程直接彈窗。不需要的,可直接刪掉該If子句
MsgBox("沒有發(fā)現(xiàn)進(jìn)程!")
Exit Sub
ElseIf TargetKill.Length = 1 Then '判斷進(jìn)程名的數(shù)量,如果只有一個(gè),就不用For循環(huán)
TargetKill(0).Kill()
End If
MsgBox("已終止" TargetKill.Length "個(gè)進(jìn)程") '彈窗提示已終止多少個(gè)進(jìn)程
Errmessages: ‘定義排錯(cuò)標(biāo)簽
If Err.Description Nothing Then ’碧祥判斷有無錯(cuò)誤,如果有,則 ↓
MsgBox(Err.Description) '當(dāng)出現(xiàn)錯(cuò)誤時(shí),彈窗提示
End If
End Sub
可根據(jù)悔旁搏需要自行修改,這個(gè)備注夠完善了吧?不會(huì)的再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