Èí¼þ¿ª·¢Åàѵ°à >> ±à³Ì¿ª·¢ >> VbScript
VBS进程判æ–代ç � |
|
¡¡¡¡±¾ÎıêÇ©£ºVBSè¿›ç¨‹åˆ¤æ– vbsæ ¸å¿ƒä»£ç �
Option Explicit
Dim objWMIService,colProcessList,strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
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
å½“ç„¶ä½ å�¯ä»¥åˆ¤æ–?winrar.exeç‰ç‰ 下é�¢é™„一个代ç �,原æ�¥ä¸æ–‡å‘½å��的,脚本之家已ç»�修改为英文命å��并且æ£å¸¸è¿�è¡Œäº†ï¼Œå› ä¸ºæ—¶é—´é—®é¢˜ï¼Œéœ€è¦�的朋å�‹å�¯ä»¥è‡ªè¡Œä¿®æ”¹ç²¾ç®€
'检测进�
proname = "qq.exe"
reName = IsProcess(proname)
If reName = True Then
msgbox "�现进程"
ElseIf reName = False Then
msgbox "没有�现进程"
End If
'检测进ç¨?优化å�Žçš„代ç �
If IsProcess("qq.exe") = True Then
msgbox "�现进程"
Else
msgbox "没有�现进程"
End If
'检测进程组
proName_all = "qq.exe|notepad.exe"
reName = IsProcessEx(proName_all)
If reName = True Then
msgbox "�现进程"
ElseIf reName = False Then
msgbox "没有�现进程"
End If
'检测进程组 优化å�Žçš„代ç �
If IsProcessEx("qq.exe|notepad.exe") = True Then
msgbox "�现进程"
Else
msgbox "没有�现进程"
End If
'结�进程 ��执行
proname = "qq.exe"
Call CloseProcess(proname, 1)
'结�进程 ��执行
proname = "qq.exe"
Call CloseProcess(proname, 0)
'结�进程���执行
proName_all = "qq.exe|notepad.exe"
Call CloseProcessEx(proName_all, 1)
'结�进程���执行
proName_all = "qq.exe|notepad.exe"
Call CloseProcessEx(proName_all, 0)
'实例应用 结�进程 ��执行 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 "结�进程失败"
Else
msgbox "结�进程�功"
End If
'实例应用 结æ�Ÿè¿›ç¨‹ å‰�å�°æ‰§è¡Œ 优化å�Žçš„代ç �(直到型循çŽ? 有些进程VBS检测ä¸�åˆ?所以先关é—å�Žæ£€æµ?
Do
Call CloseProcess("qq.exe",1)
Delay 1000
Loop While IsProcess("qq.exe")=True
msgbox "结�进程�功"
'实例应用 结�进程���执行 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 "结�进程失败"
Else
msgbox "结�进程�功"
End If
'实例应用 结æ�Ÿè¿›ç¨‹ç»?å�Žå�°æ‰§è¡Œ 优化å�Žçš„代ç �(直到型循çŽ? 有些进程VBS检测ä¸�åˆ?所以先关é—å�Žæ£€æµ?
Do
Call CloseProcessEx( "qq.exe|notepad.exe",0)
Delay 1000
Loop While IsProcessEx( "qq.exe|notepad.exe")=True
msgbox "结�进程�功"
'函数 å�程åº�部分代ç ?
'检测进�
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
'结�进程
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
'检测进程组
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
'结�进程�
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
好了这篇关于vbs进程判æ–çš„æ–‡ç« å°±ä»‹ç»�到这 |