windows WMIC:如何在特定工作目录中使用 **process call create**?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24658745/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WMIC: how to use **process call create** with a specific working directory?
提问by foxidrive
The task is to launch a program using wmic process call create "c:\folder\app.exe"
and have app.exe
access it's own support files in the app.exe home folder tree
.
任务是推出使用程序wmic process call create "c:\folder\app.exe"
,并有app.exe
在访问它自己的支持文件app.exe home folder tree
。
The batch script below illustrates the problem with WMIC silently changing the working directory, so that the support files cannot be found.
下面的批处理脚本说明了 WMIC 静默更改工作目录导致无法找到支持文件的问题。
This script creates a second batch file called one.bat
that simply types a url.txt
file from the same folder, to display www.google.com
on the console.
该脚本创建了另一个名为的批处理文件one.bat
,该url.txt
文件只是从同一文件夹中键入一个文件,以显示www.google.com
在控制台上。
When using wmic
to create the process, wmic silently changes the working directory so that one.bat
is not found and if I specify the full path as d:\abc\one.bat
then one.bat
will launch but it can't find the file to be typed called url.txt
in it's own folder.
当使用wmic
创建的过程中,WMIC默默地改变工作目录,以便one.bat
没有找到,如果我指定的完整路径d:\abc\one.bat
,然后one.bat
会推出,但它无法找到要输入的文件名为url.txt
它自己的文件夹。
If I copy the WMIC.EXE file to the same folder, it fails in the same way.
如果我将 WMIC.EXE 文件复制到同一个文件夹,它会以同样的方式失败。
@echo off
set "folder=d:\abc"
cd /d "%folder%"
(
echo.@echo off
echo.type url.txt
echo.pause
)>one.bat
(
echo.@echo off
echo.www.google.com
)>url.txt
echo this will work to launch the one.bat but the working directory is wrong and the file can't be found
wmic process call create "%folder%\one.bat"
pause
echo this will not launch one.bat because it can't be found
wmic process call create one.bat
pause
echo this will not launch one.bat as the working directory is changed
copy "%windir%\system32\wbem\wmic.exe" .
.\wmic process call create one.bat
pause
Does anyone know of a WMIC
switch that will set the working directory for this command?
有谁知道WMIC
可以为此命令设置工作目录的开关?
回答by MC ND
Run
跑
wmic process call create /?
to get the information on why this
获取有关原因的信息
wmic process call create "c:\folder\app.exe","c:\folder"
should work
应该管用