Skip to content

Instantly share code, notes, and snippets.

@jptoto
Created April 4, 2011 14:51
Show Gist options
  • Save jptoto/901763 to your computer and use it in GitHub Desktop.
Save jptoto/901763 to your computer and use it in GitHub Desktop.
Start a windows process / .exe
public class FileImporter {
public void RunImport() {
bool wait = true;
string exec = ConfigurationManager.AppSettings["Executable"];
string switches = ConfigurationManager.AppSettings["Switches"];
string parameters = ConfigurationManager.AppSettings["Params"];
string startDirectory = ConfigurationManager.AppSettings["StartDirectory"];
ILogger logger = new EventLogger();
try
{
Process proc = new Process();
proc.StartInfo.FileName = exec;
proc.StartInfo.Arguments = switches + " \"" + parameters + "\"";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.WorkingDirectory = startDirectory;
proc.Start();
}
catch (Exception ex)
{
logger.Error("Failed to execute Import Package.", ex.InnerException);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment