Suppose I open several instances of the command line and run the bat file with the command line which should close all instances of the command line except my own. All instances have the same names cmd.exe but different PIDs, how can I do this in a bat file?
2 answers
tasklist /V /FI "IMAGENAME eq cmd.exe" For each PID in the second line you will get the full window name - i.e. including the current command being executed. Here, and guided it ...
- How to navigate? The program will work on different computers and in advance how many copies and under what PID will be opened and whether they will be open at all. It is necessary to close everything except the current one. - aaa
- Sorry, did you execute the specified command? Notice that only in her window name is the text of this command itself? Or do you think that all copies will perform a list at the same time? too unlikely ... - Akina
- Yes, so how can I close all instances except the current one? I do not understand. - aaa
- Parse the first line, remove the PID from there to the environment variable. Parse the second for the presence of the specified command, if found - exit the parsing cycle, otherwise parse the next pair. And then you keel all the PIDs, except that in a variable. - Akina
- Can you please do this in the answer? - aaa
|
It is executed by one taskkill command, "nailing" all cmd.exe processes in which the taskkill command is not executed:
taskkill /fi "imagename eq cmd.exe" /fi "Windowtitle ne C:\Windows\system32\cmd.exe - taskkill*" This command assumes that the command line is called in the standard way and its interpreter is located along the path "c: \ Windows \ system32 \ cmd.exe
- Click on the "edit" button and transfer the comment from the comment to the main body of the answer. - Mikhail Rebrov
|