michelepizzi

Run an exe from C# code

Apr 6th, 2020
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System.Diagnostics;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         Process.Start("C:\\");
  8.     }
  9. }
  10.  
  11. // If your application needs cmd arguments, use something like this:
  12.  
  13. using System.Diagnostics;
  14.  
  15. class Program
  16. {
  17.     static void Main()
  18.     {
  19.         LaunchCommandLineApp();
  20.     }
  21.  
  22.     /// <summary>
  23.     /// Launch the application with some options set.
  24.     /// </summary>
  25.     static void LaunchCommandLineApp()
  26.     {
  27.         // For the example
  28.         const string ex1 = "C:\\";
  29.         const string ex2 = "C:\\Dir";
  30.  
  31.         // Use ProcessStartInfo class
  32.         ProcessStartInfo startInfo = new ProcessStartInfo();
  33.         startInfo.CreateNoWindow = false;
  34.         startInfo.UseShellExecute = false;
  35.         startInfo.FileName = "dcm2jpg.exe";
  36.         startInfo.WindowStyle = ProcessWindowStyle.Hidden;
  37.         startInfo.Arguments = "-f j -o \"" + ex1 + "\" -z 1.0 -s y " + ex2;
  38.  
  39.         try
  40.         {
  41.             // Start the process with the info we specified.
  42.             // Call WaitForExit and then the using statement will close.
  43.             using (Process exeProcess = Process.Start(startInfo))
  44.             {
  45.                 exeProcess.WaitForExit();
  46.             }
  47.         }
  48.         catch
  49.         {
  50.              // Log error.
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment