title: Process on ASP.Net server not running correctly over IIS
body: <p>I am trying to run an antivirus scan on an uploaded file in an ASP.Net web app. We are using Sophos so have access to their command line API <code>sav32cli</code>. In the code I use:</p>
  
  <pre><code>Process proc = new Process();
  proc.StartInfo.FileName = @"C:\Program Files (x86)\Sophos\Sophos Anti-Virus\sav32cli.exe";
  proc.StartInfo.Arguments = @"-remove -nc " + SavedFile;
  proc.StartInfo.Verb = "runas";
  proc.Start();
  proc.WaitForExit();
  int exitCode = proc.ExitCode;
  </code></pre>
  
  <p>When stepping through the code, when attached to the <code>w3wp</code> process on dev server, the code just jumps from one line to the next seemingly doing nothing at all. When running from code on dev server, it performs as expected scanning file and deleting if it is seen as a virus.</p>
  
  <p>The server is running IIS 8.0, and the app built in .Net Framework 4. I have changed the machine config to allow the process to run as SYSTEM account, in accordance to these instructions. <a href="https://support.microsoft.com/en-us/kb/317012#%2Fen-us%2Fkb%2F317012" rel="noreferrer">https://support.microsoft.com/en-us/kb/317012#%2Fen-us%2Fkb%2F317012</a></p>
  
  <pre><code>&lt;processModel  userName="SYSTEM" password="AutoGenerate" /&gt;
  </code></pre>
  
  <p>Is there something I'm missing? What is the best practice for this kind of implementation?</p>
  
  <p><strong>EDIT</strong>: When called, the <code>Process</code> returns an <code>ExitCode</code> of 2 (Error stopped execution), rather than the expected 0 (Scan worked, no viruses), or 3 (Scan worked, viruses found).</p>
  
  <p><strong>EDIT 2</strong>: As per comment below I changed the code to:</p>
  
  <pre><code>Process proc = new Process();
  proc.StartInfo.FileName = @"C:\Program Files (x86)\Sophos\Sophos Anti-Virus\sav32cli.exe";
  proc.StartInfo.Arguments = @"-remove -nc " + SavedFile;
  proc.StartInfo.RedirectStandardOutput = true;
  proc.StartInfo.UseShellExecute = false;
  proc.Start();
  StringBuilder output = new StringBuilder();
  
  while (!proc.StandardOutput.EndOfStream)
  {
      string line = proc.StandardOutput.ReadLine();
      output.AppendLine(line);
  }
  proc.WaitForExit();
  
  int exitCode = proc.ExitCode;
  ASPxMemo2.Text = exitCode.ToString() + Environment.NewLine + output.ToString();
  </code></pre>
  
  <p><code>output</code> is always empty when run over IIS, but is populated correctly when running from code.</p>
  
  <p><strong>EDIT 3</strong>: Instead of looking at <code>StandardOutput</code> we looked at <code>StandardError</code> and it revealed this error:</p>
  
  <blockquote>
    <p>Error initialising detection engine [0xa0040200]
          (Possible insufficient user Admin rights.)</p>
  </blockquote>
  
  <p>For the time being we are going to move to another method of virus checking, but would still like to know a possible solution if anyone has it.</p>