sdMarth
sdMarth

Reputation: 561

wmic /node:server process call create not working?

I am trying to get a server to run a python script and then save the output of the script to the computer where I call the command from. Here is the command:

wmic /node:server1 process call create "cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt"

I read this on http://blog.commandlinekungfu.com/2009/05/episode-31-remote-command-execution.html but it's an old post from 2009.

server1 is the server name of the server that I want the python script to run on. On that server, Z drive is mapped to the C drive of the computer that I am calling the command from. C:\python.exe and C:\python\hello.py is the C drive of the server. I have tried using UNC paths but that didn't work either.

All hello.py does is print "Hello" to standard out.

I have verified that the command cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt works by opening a command prompt in the server and then running it. It creates a file called result.txt which contains "Hello"

However, calling with wmic /node:server1 process call create doesn't create a file result.txt.

I have also tried

wmic /node:server1 /user:"adminUsername" /password:"adminUsersPw" process call create "cmd.exe /c C:\python.exe C:\python\hello.py >> Z:\test\result.txt"

with no luck.

When I run that command, I get something like:

Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
    ProcessId = 4116;
    ReturnValue = 0;
};

Which is strange to me because it doesn't seem like the command is being run. Any ideas?

Upvotes: 0

Views: 11334

Answers (1)

SecurityAndPrivacyGuru
SecurityAndPrivacyGuru

Reputation: 336

Using WMIC, you have to double-wrap your command in order to get the redirector (>) to the inner command (whoami) rather than the outter command (cmd). Here's an example, including output from a system I just used this on:

Cmd.exe:

$> dir \\NameOfRemoteSystem\c$\temp\z.txt
File Not Found


$> wmic /node:NameOfRemoteSystem process call create 'cmd.exe /c "whoami /all >c:\temp\z.txt"'
Executing (Win32_Process)->Create()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
        ProcessId = 20460;
        ReturnValue = 0;
};


$> dir \\NameOfRemoteSystem\c$\temp\z.txt
03/27/2019  04:40 PM            17,977 z.txt

Upvotes: 0

Related Questions