title: Difference between Process.Start and manually running exe
body: <p>Big picture: I wrote an Autodesk inventor addin.  On the close event of Inventor it launches another program I'll call purgeworkspace.exe.  purgeworkspace.exe waits until Inventor is closed, then deletes files that Inventor was using.</p>
  
  <p>Here is the relevant addin code which calls purgeworkspace.exe.</p>
  
  <pre><code>//Run as admin
  if (System.Environment.OSVersion.Version.Major &gt;= 6)
  {
      Process p = Process.Start(Properties.Settings.Default.exePath);
      p.StartInfo.Verb = "runas";
  }
  </code></pre>
  
  <p>If purgeworkspace.exe is launched from the addin, I get a IOException saying files are in use.  However if I run purgeworkspace.exe manually by double clicking the exe, it works perfect every time.  My belief is that this is due to permissions, but I don't know what.  As you can see I'm already trying to run my exe as admin, but it isn't solving the problem.</p>
  
  <p>purgeworkspace.exe works exactly as I intend when I launch it manually.  How can I call it programmatically so it runs the same way?</p>
  
  <p>Edit:
  Here's some code to demonstrate how purgeworkspace waits for inventor.  Keep in mind this code is run both when I launch it manually and when it's run from the Inventor addin.</p>
  
  <pre><code>static void Main()
  {
     while (IsProcessOpen("Inventor"))
     {
         System.Threading.Thread.Sleep(50);
     }
  }
  
  private static bool IsProcessOpen(string name)
  {
     return Process.GetProcesses().Any(clsProcess =&gt; clsProcess.ProcessName.Contains(name));
  }
  </code></pre>