CrazyForum
Would you like to react to this message? Create an account in a few clicks or log in to continue.


CrazyGamerz Gunz Forum
 
HomeLatest imagesSearchRegisterLog in

 

 GunZ Restarter

Go down 
AuthorMessage
Geujes
CG Staff
Geujes


Posts : 34
Join date : 2009-09-26
Age : 29
Location : Belgium

GunZ Restarter Empty
PostSubject: GunZ Restarter   GunZ Restarter EmptySat 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 !
Back to top Go down
http://crazyforum.heavenforum.com
 
GunZ Restarter
Back to top 
Page 1 of 1
 Similar topics
-
» Taken GunZ
» Want CrazyGamerz Gunz To back?
» Advertisement CG Gunz
» when is the gunz back?

Permissions in this forum:You cannot reply to topics in this forum
CrazyForum :: General :: Programming Section-
Jump to: