I have come across a certain problem, hopefully some of you can help me with it. Basically say I have computer 1, which executes via wmic a certain batch file (process) in computer 2, let's call it Script.bat. Depending on how the process ends, I want to get a log on computer 1 saying success/failure. For that I thought I could have 2 files on computer 1, Success.bat and Failure.bat, and run wmic again from computer 2 (inside Script.bat), either remotely running Success.bat or Failure.bat in computer 1.
Well, the problem is that if I run Script.bat via cmd in computer 2, process launches and logs get saved in computer 1; however if I run Script.bat via wmic from computer 1, process launches but I don't get logging. Is it because I can't run wmic remotely, and if so what are some alternatives? I know wmic is a little dated but changing everything to say PowerShell is probably too much work.
Thanks in advance
Edit: since apparently more info is needed, this is hopefully clearer. Success.bat
and Failure.bat
can be as simple as
echo Success>>C:\log_file.txt
;
the script in computer 2 is basically as follows:
::Script.bat
C:\foo.exe --start --user admin --password passwd
::This writes an output in my_processes.txt file
::We look for "Custom" in that file to determine the status
findstr /C:"Custom" "my_processes.txt" >nul
if %errorlevel% equ 1 (set /a flag=1)
if %flag% gtr 0 (goto thingsWentWrong)
wmic /node:COMPUTER1 process call create "C:\Success.bat"
exit /b 0
:thingsWentWrong
wmic /node:COMPUTER1 process call create "C:\Failure.bat"
exit /b 1
Now, that script is stored in computer 2, say C:\Script.bat
. If it is run "locally" from computer 2 (just by double clicking for example, or through cmd), then Success.bat
or Failure.bat
are executed in computer 1 just fine and the logs are stored; however if we run
wmic /node:COMPUTER2 process call create "C:\Script.bat"
from computer 1, foo.exe is started correctly, findstr
works as intended, but the wmic
lines are simply not run (logs in computer 1 are not created). It's as if those lines did not exist.
Apologies for not being clear enough up front.