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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:39:16  来源:igfitidea点击:

WMIC: how to use **process call create** with a specific working directory?

windowsbatch-filewmic

提问by foxidrive

The task is to launch a program using wmic process call create "c:\folder\app.exe"and have app.exeaccess 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.batthat simply types a url.txtfile from the same folder, to display www.google.comon the console.

该脚本创建了另一个名为的批处理文件one.bat,该url.txt文件只是从同一文件夹中键入一个文件,以显示www.google.com在控制台上。

When using wmicto create the process, wmic silently changes the working directory so that one.batis not found and if I specify the full path as d:\abc\one.batthen one.batwill launch but it can't find the file to be typed called url.txtin 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 WMICswitch 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

应该管用