How to stop process from .BAT file?

后端 未结 6 647
野趣味
野趣味 2020-12-14 15:25

So I have process I started from one bat file. How to stop it from another?

相关标签:
6条回答
  • 2020-12-14 16:00

    taskkill /F /IM notepad.exe this is the best way to kill the task from task manager.

    0 讨论(0)
  • 2020-12-14 16:01

    To terminate a process you know the name of, try:

    taskkill /IM notepad.exe
    

    This will ask it to close, but it may refuse, offer to "save changes", etc. If you want to forcibly kill it, try:

    taskkill /F /IM notepad.exe
    
    0 讨论(0)
  • 2020-12-14 16:06

    Here is how to kill one or more process from a .bat file.

    Step 1. Open a preferred text editor and create a new file.

    step 2. To kill one process use the 'taskkill' command, with the '/im' parameter that specifies the image name of the process to be terminated. Example:

    taskkill /im examplename.exe
    

    To 'force' kill a process use the '/f' parameter which specifies that processes be forcefully terminated. Example:

    taskkill /f /im somecorporateprocess.exe
    

    To kill more than one process you rinse and repeat the first part of step 2. Example:

    taskkill /im examplename.exe
    taskkill /im examplename1.exe
    taskkill /im examplename2.exe
    

    or

    taskkill /f /im examplename.exe
    taskkill /f /im examplename1.exe
    taskkill /f /im examplename2.exe
    

    step 3. Save your file to desired location with the .bat extension.

    step 4. click newly created bat file to run it.

    0 讨论(0)
  • 2020-12-14 16:07

    As TASKKILL might be unavailable on some Home/basic editions of windows here some alternatives:

    TSKILL processName
    

    or

    TSKILL PID
    

    Have on mind that processName should not have the .exe suffix and is limited to 18 characters.

    Another option is WMIC :

    wmic Path win32_process Where "Caption Like 'MyProcess.exe'" Call Terminate
    

    wmic offer even more flexibility than taskkill .With wmic Path win32_process get you can see the available fileds you can filter.

    0 讨论(0)
  • 2020-12-14 16:12

    Why don't you use PowerShell?

    Stop-Process -Name notepad
    

    And if you are in a batch file:

    powershell -Command "Stop-Process -Name notepad"
    powershell -Command "Stop-Process -Id 4232"
    
    0 讨论(0)
  • 2020-12-14 16:19

    When you start a process from a batch file, it starts as a separate process with no hint towards the batch file that started it (since this would have finished running in the meantime, things like the parent process ID won't help you).

    If you know the process name, and it is unique among all running processes, you can use taskkill, like @IVlad suggests in a comment.

    If it is not unique, you might want to look into jobs. These terminate all spawned child processes when they are terminated.

    0 讨论(0)
提交回复
热议问题