title: How to alter the "returnValue" property of ManagementBaseObject after running a batch file?
body: <p>The situation is: I must use ManagementBaseObject to run a batch file and get its return value (like, 0 if the commands were properly executed, 1 if something went wrong). I've tried to use "EXIT" command to set an errorlevel code, but no matter what I put as the exit code, the "returnValue" property is always 0. Is there any way to make the batch file affect that property?<br>
  here is the code (<em>instead of calling the batch file I am just executing a simple command line to make it simpler to post here, but the idea is the same</em>):</p>
  
  <pre><code>ManagementClass processClass =  new ManagementClass("Win32_Process");
  try
  {
      ManagementBaseObject inp = processClass.GetMethodParameters("Create");
      inp["CommandLine"] = @"cmd /c exit /B 1";
      ManagementBaseObject outp;
      outp = processClass.InvokeMethod("Create", inp, null);
      Console.WriteLine(outp["returnValue"]);
  }
  catch (Exception e)
  {
      Console.WriteLine(e.Message);
  }
  </code></pre>
  
  <p><strong>...but the output is always 0! What I wanted to see is 1, which is what I put as the exit code. Is it possible to do that?<br></strong>
  I know I "could" use the Process class to make it work, but using ManagementBaseObject was the only way I could find to run a batch file on a remote machine. 
  <br><br>To give a little bit of context:<br>
  I have this batch file located on a remote machine and I must run that file from my local machine. I am currently using the classes ManagementScope and ConnectionOptions to connect to the remote machine providing my credentials. After that, I create a ManagementClass associated with the remote connection, with ManagementPath set as "Win32_Process". Then, I use ManagementBaseObject to run the batch file and get its return value.<br>
  If anyone knows any other way to do this please let me know, I'm open to suggestions.<br>
  Thanks!</p>