Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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 a url.txt file from the same folder, to display www.google.com on the console.

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.

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?

like image 795
foxidrive Avatar asked Jul 09 '14 16:07

foxidrive


People also ask

How do I use the WMIC command?

Open a command prompt. Type WMIC to invoke the program, and hit enter. This will give you the WMIC command prompt, wmic:root\cli> From here, you can run WMI queries.

What are the WMIC commands?

QUIT/EXIT Exit WMIC Aliases: ALIAS - Access local system aliases [CALL] BASEBOARD - Base board management (motherboard or system board) BIOS - BIOS management (Basic input/output services) BOOTCONFIG - Boot configuration CDROM - CD-ROM COMPUTERSYSTEM - Computer system [CALL/SET] CPU - CPU CSPRODUCT - Computer system ...

What is the difference between WMI and WMIC?

The Windows Management Instrumentation (WMI) Command-Line Utility (WMIC) is a command-line utility that allows users to perform WMI operations from a command prompt. WMI is an interface providing a variety of Windows management functions.

What is WMIC path?

Wmic is an external command that is available for the following Microsoft operating systems. In Windows 10 and Windows 11, it is located at C:\Windows\System32\wbem\WMIC.exe.


1 Answers

Run

wmic process call create /?

to get the information on why this

wmic process call create "c:\folder\app.exe","c:\folder"

should work

like image 199
MC ND Avatar answered Oct 01 '22 10:10

MC ND