The challenge is to run the program with wmic process call create "c:\folder\app.exe"and have app.exeaccess to its own support files in app.exe home folder tree.
The script package below illustrates the problem with WMIC by silently changing the working directory so that support files cannot be found.
This script creates a second batch file with a name one.batthat simply types the file url.txtfrom the same folder to display www.google.comon the console.
When used wmicto create a process, wmic silently changes the working directory so that it is one.batnot found, and if I specify the full path as d:\abc\one.bat, then it one.batwill start, but it will not be able to find the file that needs to be typed url.txtin its own folder.
If I copy the WMIC.EXE file to the same folder, it will fail.
@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 switch wmicthat will set the working directory for this command?
source
share