Search code examples
vbscriptterminate

How to end a file using vbs without starting anything?


So, I'm trying to make a security system using vbs that would terminate a process. Ex: If you see "cmd.exe" Terminate cmd.exe

I have coded everything except for the terminating part. I have searched many places but all they do is first run that file and then terminate it. I want to terminate the existing running "cmd.exe"

I tried running a batch file that terminates all "cmd.exe" processes but it just terminated itself leaving the other "cmd.exe" open.

Powershell is not an option too because it's one of the process I want to terminate.

Regards,

A Viper


Solution

  • Running TaskKill Command with VB Script

    TaskKill command can terminate all existing processes whose running in same image name. For example, if the process you want to be terminated is "cmd.exe", you can use TaskKill as below in your script:

    Dim WshShell : Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.Run "CMD /C TASKKILL /F /IM cmd.exe", 0, False
    

    Above script is executed using Windows Script Host, which is not a process you want to be terminated, so this should work.