简体   繁体   中英

Suspend all processes from a specified folder

What I'm trying to do is suspend multiple processes from a single folder in Windows 7. I can get a list of such proccessses using the following commands:

WMIC PROCESS WHERE 'ExecutablePath like "c:\\users%"' GET

or

WMIC PROCESS WHERE 'ExecutablePath like "c:\\users%"' LIST

Then I need to suspend the proccesses that are returned by those commands. I can do that by using PsSuspend software. So, the only thing I have troubles with is looping through the list and executing this command for each process. It's rather easy to do in bash scripts, but how do I do it easily in Windows? I would prefer to use a .bat file or something similar, so it won't get overly complicated.

Here's an example:

@Echo Off
SetLocal EnableExtensions

Rem Command
(Set WC=Process)
Rem Filter
(Set WF=ExecutablePath Like)
Rem Value
(Set FV=%UserProfile%)
Rem Output
(Set RO=ProcessID)
Rem Run
(Set RC=PsSuspend)

For /F "UseBackQ Skip=1" %%A In (
    `WMIC %WC% Where "%WF% '%FV:\=\\%%%'" Get %RO%`) Do For %%B In (%%A
    ) Do %RC% %%B

I changed line 9 to %UserProfile% you can change it back to C:\\Users if you think I've assumed wrongly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM