【问题标题】:WMIC ProcessID BatchWMIC ProcessID 批处理
【发布时间】:2017-12-13 09:13:45
【问题描述】:

我正在批量使用 WMIC 来获取进程 ID。 如何在 WMIC 命令中使用 CommandLine 参数。

我已经尝试过这样的事情:

for /f "skip=1 tokens=*" %%i in ('wmic process where "name^="Example.exe" and CommandLine like '%Example%'" get ProcessId') do (echo attach %%i >> ".\my-script.txt")    

我只使用参数名称得到一个进程。但问题是我有三个同名的进程。

【问题讨论】:

  • "name^="Example.exe" 对我来说似乎是错误的。
  • 试试这样 for /f "skip=1 tokens=*" %%i in ('wmic process where name^="Example.exe" get ProcessId') do (echo attach %% i >> ".\my-script_1.txt") 。您将获得 PID。

标签: windows batch-file command-line process wmic


【解决方案1】:

试试这样:

@echo off

for /f "usebackq tokens=* delims=" %%a in (`wmic process where "name='Example.exe' and CommandLine like '%%Example%%'" get ProcessID /Format:value`) do (
    for /f "tokens=* delims=" %%z in ("%%a") do set "%%z"
)
echo %processid%

您需要将% 加倍,否则它将被 cmd.exe 解析为变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-21
    • 1970-01-01
    • 1970-01-01
    • 2019-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多