WMIC: how to use **process call create** with a specific working directory?
Run
wmic process call create /?
to get the information on why this
wmic process call create "c:\folder\app.exe","c:\folder"
should work
foxidrive
Updated on August 05, 2022Comments
-
foxidrive almost 2 years
The task is to launch a program using
wmic process call create "c:\folder\app.exe"
and haveapp.exe
access it's own support files in theapp.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.
This script creates a second batch file called
one.bat
that simply types aurl.txt
file from the same folder, to displaywww.google.com
on the console.When using
wmic
to create the process, wmic silently changes the working directory so thatone.bat
is not found and if I specify the full path asd:\abc\one.bat
thenone.bat
will launch but it can't find the file to be typed calledurl.txt
in it's own folder.If I copy the WMIC.EXE file to the same folder, it fails in the same way.
@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? -
foxidrive almost 10 yearsThank you MC ND as your suggestion works fine. I tried
wmic process call create /?
and I can't follow the help on that screen. There is not one comma on it. :) -
MC ND almost 10 years@foxidrive, sorry, you are right. I forget to mention it. My fault. Fortunately
wmic
is kind enough to suggest the correct syntax when the wrong one is used. -
foxidrive almost 10 yearsAhh, thanks. That's useful. EDIT: I tried several invalid commands and I couldn't get any help with the syntax. Can you copy the command you used to get the help? That could be useful knowledge to get WMIC to help me in future.
-
MC ND almost 10 years@foxidrive, i just tried
wmic call create "calc.exe" "c:\"
to get (sorry, spanish windows locale)Sugerencia: <lista_parámetros> = <parámetro> [, <lista_parámetros>]
-
Kevin over 2 yearsdetecting if run from git bash, then relaunching CMD batch script with current directory, if "x%PS1%x" neq "xx" ( wmic process call create "C:\path\build_driver.bat","%cd%" GOTO END )