16

How can I terminate process using vbscript. PLEASE NOTE, I need to terminate process that runs under windows 64-bit environment as native 64 (not using select * from win_32_Process)

Thanks,

Mark
  • 163
  • 1
  • 1
  • 4

4 Answers4

36

The Win32_Process class provides access to both 32-bit and 64-bit processes when the script is run from a 64-bit command shell.

If this is not an option for you, you can try using the taskkill command:

Dim oShell : Set oShell = CreateObject("WScript.Shell")

' Launch notepad '
oShell.Run "notepad"
WScript.Sleep 3000

' Kill notepad '
oShell.Run "taskkill /im notepad.exe", , True
Helen
  • 87,344
  • 17
  • 243
  • 314
3

Just type in the following command: taskkill /f /im (program name) To find out the im of your program open task manager and look at the process while your program is running. After the program has run a process will disappear from the task manager; that is your program.

Saji Samsaji
  • 31
  • 1
  • 4
2

I know I am late to the game LOL, but this is what I did to kill SmartScreen.

  1. Create text file KillSmartScreen.vbs

  2. Edit with Notepad:

    Dim oShell : Set oShell = CreateObject("WScript.Shell")
    
    'Kill smartscreen.exe  aka Windows Defender SmartScreen 
    
    oShell.Run "taskkill /f /im smartscreen.exe"
    
  3. Double click KillSmartScreen.vbs to run.

Works like a champ.

EAmez
  • 837
  • 1
  • 9
  • 25
Eric Moon
  • 101
  • 3
0

Here is the code to exit from the loop:

Function main()
do while (SOME_CONDITION)
    If SOMETHING_1 = 1 Then
        DO_SOMETHIONG()
        Exit Do
    End If
loop
End Function

main()
Shubham Verma
  • 8,783
  • 6
  • 58
  • 79