主頁 > 知識庫 > VBS進(jìn)程判斷代碼

VBS進(jìn)程判斷代碼

熱門標(biāo)簽:神行者美術(shù)館地圖標(biāo)注 如何用機器人進(jìn)行電銷 東營快遞外呼系統(tǒng) 百度地圖標(biāo)注點距離代碼 哪里有便宜的地圖標(biāo)注公司 佛山真人電銷機器人廠家 地圖標(biāo)注政府哪個部門管 除了地圖標(biāo)注還有這種生意嗎 齊齊哈爾高德地圖標(biāo)注店

vbs核心代碼

Option Explicit
Dim objWMIService,colProcessList,strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\"  strComputer  "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'excel.exe'")
If colProcessList.Count>0 Then
	MsgBox "檢測到EXCEL程序運行中,程序退出!"
	WScript.Quit
End If
Set colProcessList = Nothing
Set objWMIService = Nothing
WScript.Quit

當(dāng)然你可以判斷 winrar.exe等等

下面附一個代碼,原來中文命名的,腳本之家已經(jīng)修改為英文命名并且正常運行了,因為時間問題,需要的朋友可以自行修改精簡

'檢測進(jìn)程
proname = "qq.exe"
reName = IsProcess(proname)
If reName = True Then
  msgbox "發(fā)現(xiàn)進(jìn)程"
ElseIf reName = False Then
  msgbox "沒有發(fā)現(xiàn)進(jìn)程"
End If
'檢測進(jìn)程 優(yōu)化后的代碼
If IsProcess("qq.exe") = True Then 
  msgbox "發(fā)現(xiàn)進(jìn)程"
Else 
  msgbox "沒有發(fā)現(xiàn)進(jìn)程"
End If
'檢測進(jìn)程組
proName_all = "qq.exe|notepad.exe"
reName = IsProcessEx(proName_all)
If reName = True Then
  msgbox "發(fā)現(xiàn)進(jìn)程"
ElseIf reName = False Then
  msgbox "沒有發(fā)現(xiàn)進(jìn)程"
End If
'檢測進(jìn)程組 優(yōu)化后的代碼
If IsProcessEx("qq.exe|notepad.exe") = True Then 
  msgbox "發(fā)現(xiàn)進(jìn)程"
Else 
  msgbox "沒有發(fā)現(xiàn)進(jìn)程"
End If
'結(jié)束進(jìn)程 前臺執(zhí)行
proname = "qq.exe"
  Call CloseProcess(proname, 1)
'結(jié)束進(jìn)程 后臺執(zhí)行
proname = "qq.exe"
  Call CloseProcess(proname, 0)
  '結(jié)束進(jìn)程組 前臺執(zhí)行
proName_all = "qq.exe|notepad.exe"
  Call CloseProcessEx(proName_all, 1)
'結(jié)束進(jìn)程組 后臺執(zhí)行
proName_all = "qq.exe|notepad.exe"
  Call CloseProcessEx(proName_all, 0)
'實例應(yīng)用 結(jié)束進(jìn)程 前臺執(zhí)行 10秒超時
proname = "qq.exe"
For i=1 to 10
  Call CloseProcess(proname,1)
  Delay 1000
  reName = IsProcess(proname)
  If reName = False Then
    Exit For
  End If
Next
If reName=True Then
  msgbox "結(jié)束進(jìn)程失敗"
Else
  msgbox "結(jié)束進(jìn)程成功"
End If
'實例應(yīng)用 結(jié)束進(jìn)程 前臺執(zhí)行 優(yōu)化后的代碼(直到型循環(huán)) 有些進(jìn)程VBS檢測不到 所以先關(guān)閉后檢測
Do
  Call CloseProcess("qq.exe",1)
  Delay 1000
Loop While IsProcess("qq.exe")=True
msgbox "結(jié)束進(jìn)程成功"
'實例應(yīng)用 結(jié)束進(jìn)程組 后臺執(zhí)行 10秒超時
proName_all = "qq.exe|notepad.exe"
For j=1 to 10
  Call CloseProcessEx(proName_all,0)
  Delay 1000
  reName = IsProcessEx(proName_all)
  If reName = False Then
    Exit For
  End If
Next
If reName=True Then
  msgbox "結(jié)束進(jìn)程失敗"
Else
  msgbox "結(jié)束進(jìn)程成功"
End If
'實例應(yīng)用 結(jié)束進(jìn)程組 后臺執(zhí)行 優(yōu)化后的代碼(直到型循環(huán)) 有些進(jìn)程VBS檢測不到 所以先關(guān)閉后檢測
Do
  Call CloseProcessEx( "qq.exe|notepad.exe",0)
  Delay 1000
Loop While IsProcessEx( "qq.exe|notepad.exe")=True
msgbox "結(jié)束進(jìn)程成功"
'函數(shù) 子程序部分代碼
'檢測進(jìn)程
Function IsProcess(ExeName)
  Dim WMI, Obj, Objs,i
  IsProcess = False
  Set WMI = GetObject("WinMgmts:")
  Set Objs = WMI.InstancesOf("Win32_Process")
  For Each Obj In Objs
    If InStr(UCase(ExeName),UCase(Obj.Description)) > 0 Then
      IsProcess = True
      Exit For
    End If
  Next
  Set Objs = Nothing
  Set WMI = Nothing
End Function
'結(jié)束進(jìn)程
Sub CloseProcess(ExeName,RunMode)
  dim ws
  Set ws = createobject("Wscript.Shell")
  ws.run "cmd.exe /C Taskkill /f /im "  ExeName,RunMode
  Set ws = Nothing
End Sub
'檢測進(jìn)程組
Function IsProcessEx(ExeName)
  Dim WMI, Obj, Objs,ProcessName,i
  IsProcessEx = False
  Set WMI = GetObject("WinMgmts:")
  Set Objs = WMI.InstancesOf("Win32_Process")
  ProcessName=Split(ExeName,"|")
  For Each Obj In Objs
    For i=0 to UBound(ProcessName)
      If InStr(UCase(ProcessName(i)),UCase(Obj.Description)) > 0 Then
        IsProcessEx = True
        Exit For
      End If
    Next
  Next
  Set Objs = Nothing
  Set WMI = Nothing
End Function
'結(jié)束進(jìn)程組
Sub CloseProcessEx(ExeName,RunMode)
  dim ws,ProcessName,CmdCode,i
  ProcessName = Split(ExeName, "|")
  For i=0 to UBound(ProcessName)
    CmdCode=CmdCode  " /im "  ProcessName(i)
  Next
  Set ws = createobject("Wscript.Shell")
  ws.run "cmd.exe /C Taskkill /f"  CmdCode,RunMode
  Set ws = Nothing
End Sub

好了這篇關(guān)于vbs進(jìn)程判斷的文章就介紹到這

您可能感興趣的文章:
  • DOS中判斷進(jìn)程是否存在的方法
  • windows服務(wù)器維護經(jīng)驗小結(jié)(rsync,serv_u)

標(biāo)簽:銅川 邢臺 湖州 四平 西安 文山 鶴壁

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《VBS進(jìn)程判斷代碼》,本文關(guān)鍵詞  VBS,進(jìn)程,判斷,代碼,VBS,進(jìn)程,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《VBS進(jìn)程判斷代碼》相關(guān)的同類信息!
  • 本頁收集關(guān)于VBS進(jìn)程判斷代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章