WMIC:如何在当前工作目录中使用“流程调用创建”

时间:2018-07-16 02:41:14

标签: windows wmic

我想使用wmic Process call create在当前工作目录中打开CMD。但是,当我添加"%~dp0"来指定目录时,以下命令不会输出任何内容。

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0" ^| find "ProcessId"') do echo PID = %%I

据我所知%~dp0将以\结尾,所以%~dp0将会像C:\Users\

如果我删除\,它将起作用。例如:以下命令将起作用。

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"C:\Users" ^| find "ProcessId"') do echo PID = %%I

如何在动态工作目录中使用wmic Process call create

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。我必须添加一个尾随点(.)。

%~dp0%~dp0.

for /F "tokens=2 delims==; " %%I in ('wmic Process call create "cmd.exe"^,"%~dp0." ^| find "ProcessId"') do echo PID = %%I

了解更多:How to get the path of a batch script without the trailing backslash in a single command?