title: Use powershell to run an installation from C#
body: <p>The problem is installation shutdown and uninstall the windows service, but stopped and hang in there in the background. If I run the script outside the code, everything works. just wondering if it is possible to call installation this way in the code and how?</p>
  
  <p>The application is running as Windows Service. This service will call a powershell script to run an installation. In the installation, it will shutdown the Windows service and re-install. the code is below:</p>
  
  <pre><code>   string filepath = Path.Combine(requiredFiles.First().Value.Path);
          script = $"Start-Process -FilePath {filepath} -ArgumentList \"/S 
          /Q localhost\"";
          _Log.Info($"powershell running: {script}");
          var process = new Process();
          process.StartInfo.UseShellExecute = false;
          process.StartInfo.CreateNoWindow = true;
          process.StartInfo.FileName = @"C:\windows\system32\windowspowershell\v1.0\powershell.exe";
          process.StartInfo.Arguments = script;
  
          process.Start();
          process.WaitForExit();
  </code></pre>
  
  <p>Thank you very much for your help.
  I am pretty sure RunspaceFactory will not work.</p>