Windows – How to call a cmd on a remote server without having the absolute path

batch filescriptwindows

I would like to call a cmd (let's call it x.cmd) on a remote server. The x.cmd will return a log file in a log folder. Problem is this log folder in x.cmd doesn't have an absolute path (just a relative path like log\ ) so if I do

wmic /node:server process call create "serverpath\x.cmd"

it will process x.cmd but save the log file into system32 or somewhere I assume. If I add cd /d %~dp0 into x.cmd then it works fine. Unfortunately I am not allowed to touch x.cmd. Just wondering is there any other way to call the x.cmd without modifying it and also the correct output. Thanks.

JS

Best Answer

http://msdn.microsoft.com/en-us/library/windows/desktop/aa389388(v=vs.85).aspx

the second parameter that wmic process accepts is the directory.You can try this:

wmic /node:server process call create "serverpath\x.cmd" , "c:\path\to\x.cmd"

or

wmic /node:server process call create CommandLine="serverpath\x.cmd" CurrentDirectory="c:\path\to\x.cmd"

You might need one additional call of net share on the remote machine to get exact location of the directory. something like this:

wmic /node:server process call create "cmd /c \"net share ^> \\\\myshare\\server.shares.txt \""
Related Question