Post: [C#] How to Use Processes
03-01-2013, 10:05 PM #1
Sonoro
I like anteaters
(adsbygoogle = window.adsbygoogle || []).push({}); Hello, Sonoro here, i will show you how to use processes on C# , this way you can use MS-DOS commands or command lines app via your application.

• First of all, create one button or whatever you need to use.

• Import using System.Diagnostics
    using System.Diagnostics;


• Create a new process
     Process MyProcess = new Process(); or System.Diagnostics.Process p = new System.Diagnostics.Process();

     MyProcess.StartInfo.UseShellExecute = false;


- Optional : depending on if you want to show the terminal window or keep it hidden, you can use this code, true or false depending on if you want to hide it or not.:
    MyProcess.StartInfo.CreateNoWindow = true/false;



• Now we would have to set what command line app we are going to use with this process. I will be using CMD
    MyProcess.StartInfo.FileName = "cmd";


- Note : if you want to use a command line app which is not a system's default one, you would have to put this in the program directory.


• Now that we have set everything , we need to specify the arguments, basically the string that our process must execute, associated to the app we specified. So let's go:
    MyProcess.StartInfo.Arguments = "shutdown /s";


- Note : Here are the arguments our process will use. This way my process will execute "cmd shutdown /s".


• We are almost done, the last thing we need to do is to start the process, like this:
    MyProcess.Start();


Then just wait for it to execute the string:
    MyProcess.WaitForExit();


So just close it when it's done.
    MyProcess.Exit();




Well, the tutorial is ended :nerd: , hope you liked it and learned a bit. Stay tuned for other tutorials coming soon.
(adsbygoogle = window.adsbygoogle || []).push({});

The following 2 users say thank you to Sonoro for this useful post:

Machine,
03-01-2013, 11:59 PM #2
Pichu
RIP PICHU.
You forgot to tell them that they need to import - System.Diagnostics; to use Process or else they will have to call it every time:

Either us the following;
    
using System.Diagnostics;

Process p = new Process();


or

    
System.Diagnostics.Process p = new System.Diagnostics.Process();
03-02-2013, 01:11 AM #3
Originally posted by xSonoro View Post
Hello, Sonoro here, i will show you how to use processes on C# , this way you can use MS-DOS commands or command lines app via your application.

• First of all, create one button or whatever you need to use.

• Create a new process
     Process MyProcess = new Process();

     MyProcess.StartInfo.UseShellExecute = false;


- Optional : depending on if you want to show the terminal window or keep it hidden, you can use this code, true or false depending on if you want to hide it or not.:
    MyProcess.StartInfo.CreateNoWindow = true/false;



• Now we would have to set what command line app we are going to use with this process. I will be using CMD
    MyProcess.StartInfo.FileName = "cmd";


- Note : if you want to use a command line app which is not a system's default one, you would have to put this in the program directory.


• Now that we have set everything , we need to specify the arguments, basically the string that our process must execute, associated to the app we specified. So let's go:
    MyProcess.StartInfo.Arguments = "shutdown /s";


- Note : Here are the arguments our process will use. This way my process will execute "cmd shutdown /s".


• We are almost done, the last thing we need to do is to start the process, like this:
    MyProcess.Start();


Then just wait for it to execute the string:
    MyProcess.WaitForExit();


So just close it when it's done.
    MyProcess.Exit();




Well, the tutorial is ended :nerd: , hope you liked it and learned a bit. Stay tuned for other tutorials coming soon.



there is much much more to this man...
03-02-2013, 09:35 AM #4
Sonoro
I like anteaters
Originally posted by Jakes625PS3 View Post
there is much much more to this man...


This is something so basic Jake, just letting started some members, will write something more advanced really soon, since i started loving this section.

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo