Geujes CG Staff
Posts : 34 Join date : 2009-09-26 Age : 29 Location : Belgium
| Subject: GunZ Restarter Sat Sep 26, 2009 7:23 pm | |
| CrazyGamerz Gunz, Restarter
I've written this a few hours back in C# for CG. It restarts the server and agents when necessary.
Anyway, I wrote it in C# because I was too lazy to use C++. Here's the function I wrote:
- Code:
-
//Function that checks of the process given is running. public static bool IsProcessRunning(string ProcessName, string Path) { //Let's check all the processes running. foreach (Process clsProcess in Process.GetProcesses()) { //If the processname it's currently looking at contains the ProcessName given, it exists so it returns true. if (clsProcess.ProcessName.Contains(ProcessName)) { //Let's write it to the console. Console.WriteLine(ProcessName + " is still running!"); return true; } } //No way, the process isn't there anymore! Console.WriteLine(ProcessName + " is not running anymore!"); //Let's start the process. Since the second argument contains the full path, we can simply use Process.Start(). try { Process.Start(Path); Console.WriteLine("Starting the process. If no error pops up, it went all fine."); } catch { //Starting failed. Console.WriteLine(Path + " has NOT been executed. Please check if the path given exists."); } return false; } It's pretty well commented. Here's an example on how to use it: - Code:
-
//Is paint started? The second argument is if the process needs to be restarted. IsProcessRunning("mspaint", "C:/WINDOWS/system32/mspaint.exe"); CrazyGamerz Team ! | |
|