//檢測(cè)進(jìn)程
進(jìn)程名 = "qq.exe"
返回值 = IsProcess(進(jìn)程名)
If 返回值 = True Then
MessageBox "發(fā)現(xiàn)進(jìn)程"
ElseIf 返回值 = False Then
MessageBox "沒(méi)有發(fā)現(xiàn)進(jìn)程"
End If
//檢測(cè)進(jìn)程 優(yōu)化后的代碼
If IsProcess( "qq.exe" ) = True Then
MessageBox "發(fā)現(xiàn)進(jìn)程"
Else
MessageBox "沒(méi)有發(fā)現(xiàn)進(jìn)程"
End If
//檢測(cè)進(jìn)程組
進(jìn)程組 = "qq.exe|notepad.exe"
返回值 = IsProcessEx(進(jìn)程組)
If 返回值 = True Then
MessageBox "發(fā)現(xiàn)進(jìn)程"
ElseIf 返回值 = False Then
MessageBox "沒(méi)有發(fā)現(xiàn)進(jìn)程"
End If
//檢測(cè)進(jìn)程組 優(yōu)化后的代碼
If IsProcessEx( "qq.exe|notepad.exe" ) = True Then
MessageBox "發(fā)現(xiàn)進(jìn)程"
Else
MessageBox "沒(méi)有發(fā)現(xiàn)進(jìn)程"
End If
//結(jié)束進(jìn)程 前臺(tái)執(zhí)行
進(jìn)程名 = "qq.exe"
Call CloseProcess(進(jìn)程名, 1)
//結(jié)束進(jìn)程 后臺(tái)執(zhí)行
進(jìn)程名 = "qq.exe"
Call CloseProcess(進(jìn)程名, 0)
//結(jié)束進(jìn)程組 前臺(tái)執(zhí)行
進(jìn)程組 = "qq.exe|notepad.exe"
Call CloseProcessEx(進(jìn)程組, 1)
//結(jié)束進(jìn)程組 后臺(tái)執(zhí)行
進(jìn)程組 = "qq.exe|notepad.exe"
Call CloseProcessEx(進(jìn)程組, 0)
//實(shí)例應(yīng)用 結(jié)束進(jìn)程 前臺(tái)執(zhí)行 10秒超時(shí)
進(jìn)程名 = "qq.exe"
For 10
Call CloseProcess(進(jìn)程名,1)
Delay 1000
返回值 = IsProcess(進(jìn)程名)
If 返回值 = False Then
Exit For
End If
Next
If 返回值= True Then
MessageBox "結(jié)束進(jìn)程失敗"
Else
MessageBox "結(jié)束進(jìn)程成功"
End If
//實(shí)例應(yīng)用 結(jié)束進(jìn)程 前臺(tái)執(zhí)行 優(yōu)化后的代碼(直到型循環(huán)) 有些進(jìn)程VBS檢測(cè)不到 所以先關(guān)閉后檢測(cè)
Do
Call CloseProcess( "qq.exe" ,1)
Delay 1000
Loop While IsProcess( "qq.exe" )= True
MessageBox "結(jié)束進(jìn)程成功"
//實(shí)例應(yīng)用 結(jié)束進(jìn)程組 后臺(tái)執(zhí)行 10秒超時(shí)
進(jìn)程組 = "qq.exe|notepad.exe"
For 10
Call CloseProcessEx(進(jìn)程組,0)
Delay 1000
返回值 = IsProcessEx(進(jìn)程組)
If 返回值 = False Then
Exit For
End If
Next
If 返回值= True Then
MessageBox "結(jié)束進(jìn)程失敗"
Else
MessageBox "結(jié)束進(jìn)程成功"
End If
//實(shí)例應(yīng)用 結(jié)束進(jìn)程組 后臺(tái)執(zhí)行 優(yōu)化后的代碼(直到型循環(huán)) 有些進(jìn)程VBS檢測(cè)不到 所以先關(guān)閉后檢測(cè)
Do
Call CloseProcessEx( "qq.exe|notepad.exe" ,0)
Delay 1000
Loop While IsProcessEx( "qq.exe|notepad.exe" )= True
MessageBox "結(jié)束進(jìn)程成功"
//函數(shù) 子程序部分代碼
//檢測(cè)進(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
//檢測(cè)進(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
|
評(píng)論(0人參與,0條評(píng)論)
發(fā)布評(píng)論
最新評(píng)論