Script For instantly disabling multiple system processes with vbs

Source: Internet
Author: User

Program The test environment is Windows xp_sp2, which is mainly used to instantly interrupt processes in batches when multiple processes need to be interrupted in the system. CopyCode The Code is as follows :'----------------------------------------------------------------------------------
On Error resume next
Set FS = Createobject ("scripting. FileSystemObject ")
Set OS = Createobject ("wscript. Shell ")
Set os0 = Createobject ("Shell. Application ")
Set D0 = Createobject ("scripting. Dictionary ")
Set WMI = GetObject ("winmgmts :\\.")
Set pro_s = WMI. instancesof ("win32_process ")

'------------- Create a temporary text file, input the current process to the text file, and open it through notepad
'--------- Simultaneously pass the process serial number and PID to Dictionary (D0)
Filename = FS. gettempname
Set F1 = FS. createtextfile (filename, true)
MSG = "no." & vbtab & "name" & vbtab & "PID" & vbtab & "program file" & vbtab & now & CHR (10)
F1.writeline (MSG)
N = 1
For each P in pro_s
F1.writeline (N & "." & P. Name & "," & P. Handle & "," & P. CommandLine & CHR (10 ))
D0.add "& N, trim (P. Handle)
N = n + 1
Next
F1.close
Os0.minimizeall
OS. EXEC "notepad.exe" & filename
Wscript. Sleep 500

'-------------- Wait for the user to enter the serial number column related to the process to be interrupted, and close and delete the temporary text file.
X = inputbox ("Please follow the content in" & filename & "+ CHR (10) + _
"Select the serial number of the process to be interrupted at the same time:" + CHR (10) + _
"(Use ',' for example, '1, 3, 5, 7, 11 ')", "select ")
OS. appactivate filename & "-Notepad"
OS. sendkeys "% FX"
Wscript. Sleep 500
FS. deletefile filename

'-------- If the user cancels the operation, exit the program
If X = "" Then wscript. Quit
'-------- Pass the sequence numbers in the serial number column entered by the user to an array XS
Xs = Split (x, ",",-1, 1)
'----------- Proofread the serial number column entered by the user, mark the repeated serial number as-2, and calculate the actual number of serial numbers
For I = 0 to ubound (XS) '--- repeat the input content with a double loop, and mark others as-1
For n = 0 to ubound (XS)
If n = I then
N = n + 1
If n> ubound (XS) Then exit
End if
If trim (XS (N) = trim (XS (I) or _
Trim (XS (N) = "" then
Xs (n) = "-1"
End if
Next
Next

W = 0' ---- remove the numbers that are not actually available and calculate the number.
For I = 0 to ubound (XS)
If d0.exists (XS (I) = false then
Xs (I) = "-2"
W = W + 1
End if
Next

W = (ubound (XS) + 1-w) '--- obtain the number of available serial numbers
'------------ Exit the program if no serial number is entered in the sequence
If W = 0 then
Msgbox "The list of processes to be interrupted is blank! "
Wscript. Quit
End if

'------------- Process interruption based on user input
M = 0
For I = 0 to ubound (XS)
If Xs (I) <> "-2" then' --- only real available sequence numbers are involved in the loop.
For each P in pro_s
If trim (P. Handle) = trim (D0 (XS (I) then' --- if the PID Number of the process needs to be interrupted, try to interrupt it.
P_name = P. Name
Pd = P. Terminate ()
If Pd = 0 then '--- determines whether the attempt to interrupt the process is successful.
MSG = p_name & "process interrupted successfully! "
M = m + 1
Else
MSG = p_name & "process interruption failed! "
End if
OS. Popup MSG, 1, "notification", 64 + 0
End if
Next
End if
Next

OS. Popup W & "target processes, which have been interrupted" & M & ", 5," notification ", 64 + 0
Wscript. Quit

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.