A small vbs_vbs that kills the specified process name

Source: Internet
Author: User

Here is a small section to kill the name of the specified process small VBS, I hope to help.

Function Killproc (strprocname) on
Error Resume Next
 Set objWMIService = GetObject ("winmgmts:{ Impersonationlevel=impersonate}!\\.\root\cimv2 ")
 Set arrprocesses = objWMIService.ExecQuery (" SELECT * from Win32 _process where Name = ' &strProcName& ' ' for each
 proccess in arrprocesses
 proccess. Terminate 0 
 Next End
Function

VBS command-process action code (detection process, end process)

Detect process Process name = "Qq.exe" return value = isprocess (process name) If return value = True Then MessageBox "discovery process" ElseIf return value = False Then MessageBox "not found  Thread "End If//detect process Optimized code If isprocess (" qq.exe ") = True Then MessageBox" discovery process "Else MessageBox" no processes found "if//Detect process Group process Group = "Qq.exe|notepad.exe" return value = Isprocessex (process group) If return value = True Then MessageBox "discovery process" ElseIf return value = False Then MessageBox "No
Discovery process "End If//Detect process Group optimized code If isprocessex (" qq.exe|notepad.exe ") = True Then MessageBox" discovery process "Else MessageBox" no process found " End If//ending process foreground execution process name = "Qq.exe" Call closeprocess (process name, 1)//End process Background execution process name = "Qq.exe" Call closeprocess (process name, 0)//End Process Group before Console execution Process group = "Qq.exe|notepad.exe" Call Closeprocessex (process Group, 1)//End Process Group Background execution Process group = "Qq.exe|notepad.exe" Call Closeprocessex (Process group , 0)//instance application end process foreground Execution 10 second timeout process name = "Qq.exe" for Ten call Closeprocess (process name, 1) Delay 1000 return value = isprocess (process name) If return value = False Then Exit for the end if Next if return value =true Then MessageBox "End process failed" Else MessageBox "End Process Success" ended if//instance application to terminate process foreground execution optimized code (until type loop) Some process VBS is not detected so it is closed before detection
Do called closeprocess ("Qq.exe", 1) Delay 1000 loop while isprocess ("Qq.exe") =true MessageBox "End Process succeeded"//instance application end Process group background execution 10 seconds  Timeout process group = "Qq.exe|notepad.exe" for Ten call Closeprocessex (process Group, 0) Delay 1000 return value = Isprocessex (process group) If return value = False Then Exit For End If Next if return value =true Then MessageBox "finish process failed" Else MessageBox "End process Success" End IF//instance application ending process group background executing optimized code (until type loop) some processes The VBS is not detected so it is first closed to detect do call Closeprocessex ("Qq.exe|notepad.exe", 0) Delay 1000 loop while Isprocessex ("Qq.exe|notepad.exe")  =true MessageBox "End Process Success"//Function subroutine part code//Detect Process 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 Isproce
SS = True Exit for end If Next Set objs = Nothing Set WMI = no end Function//ending process Sub closeprocess (Exename,runmode) Dim ws Set WS = CreateObject ("Wscript.Shell") ws.run "cmd.exe/c taskkill/f/im" & Exename,runmode Setws = Nothing end Sub//Detect Process Group 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 (i)), ProcessName (UCase)) <> 0 obj.description Isprocessex = True Exit for-If next Next set objs = Nothing Set WMI = no end Function//ending process group 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.shel L ") ws.run" cmd.exe/c taskkill/f "& cmdcode,runmode Set ws = Nothing end Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.