Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 11-03-2007, 09:47 PM   #1 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default Process Stopping

Code:
static void stopProcess()
        {
                System.Console.Write("What process would you like to stop?: ");
                string pname = System.Console.ReadLine();
                Process[] processes = Process.GetProcessesByName(pname);
                if ((pname.Contains(Convert.ToString(processes))))
                {
                    foreach (Process process in processes)
                    {
                        process.Kill();
                        System.Console.WriteLine(pname + " has been stopped.");
                    }
                }
                else if (!(pname.Contains(processes.ToString())) && pname != "None")
                {
                    System.Console.WriteLine(pname + " is not a valid process name. Please try again.");
                    stopProcess();
                }
                else if (pname == "None")
                {
                        CommandHandler(commandGiven);
                }
        }
I seem to be having some difficulties with this for some odd reason. I don't get any errors, it just simlpy doesn't work. Help? Thanks much!
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Old 11-03-2007, 10:24 PM   #2 (permalink)
Forum Expert
 
arul's Avatar
 
Join Date: Jan 2005
Location: Hic sunt leones ...
Age: 21
Posts: 1,280
Send a message via MSN to arul
Default

Code:
if ((pname.Contains(Convert.ToString(processes))))
Get rid of this line, makes no sense.
__________________
Angels are falling the very last time, down they're burning in hate and decline, unfaithful and violent we're breaking the spell, we're god, we're scissor, in heaven and hell!
arul is offline   Reply With Quote
Old 11-03-2007, 10:58 PM   #3 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Code Block Update:
Code:
static void stopProcess()
        {
            System.Console.Write("What process would you like to stop?: ");
            string pname = System.Console.ReadLine().ToUpper();
            Process[] processes = Process.GetProcessesByName(pname);
            foreach (Process process in processes)
            {
                if (Convert.ToString(process).ToUpper().Contains(pname.ToUpper()))
                {
                    process.Kill();
                    System.Console.WriteLine(pname + " has been stopped.");
                }
                else if (!(Convert.ToString(process).ToUpper().Contains(pname.ToUpper())) && !(pname == "None"))
                {
                    System.Console.WriteLine(pname + " is not a valid process name. Please try again.");
                    stopProcess();
                }
                else if (pname == "None")
                {
                    System.Console.WriteLine("Process stopper canceled.");
                    CommandHandler(commandGiven);
                }
            }
        }
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.

Last edited by Storm33229; 11-03-2007 at 11:54 PM.
Storm33229 is offline   Reply With Quote
Old 11-04-2007, 12:18 AM   #4 (permalink)
Master of the Internet
 
Joeku's Avatar
 
Join Date: Feb 2005
Location: ShatteredSosaria.com
Posts: 9,252
Default

Process Members

Try this:
Code:
static void stopProcess()
{
	System.Console.Write("What process would you like to stop?: ");
	string pname = System.Console.ReadLine().ToUpper();
	Process[] processes = Process.GetProcessesByName(pname);
	Process process = null;

	if( pname == "NONE" )
	{
		System.Console.WriteLine("Process stopper canceled.");
		CommandHandler(commandGiven);
		return;
	}

	string temp;
	foreach (Process p in processes)
	{
		temp = p.ProcessName.ToUpper();

		//if (Convert.ToString(process).ToUpper().Contains(pname.ToUpper()))
		if( temp.IndexOf( pname ) > -1 )
		{
			process = p;
			break;
		}
	}

	if( process != null )
	{
		process.Kill();
		System.Console.WriteLine(process.ProcessName + " has been stopped.");
	}
	else
	{
		System.Console.WriteLine(pname + " is not a valid process name. Please try again.");
		stopProcess();
	}
}
Joeku is offline   Reply With Quote
Old 11-04-2007, 12:29 AM   #5 (permalink)
Forum Expert
 
Join Date: Jul 2003
Location: Arizona
Age: 18
Posts: 3,149
Send a message via AIM to Storm33229 Send a message via Yahoo to Storm33229
Default

Quote:
Originally Posted by Joeku View Post
Process Members

Try this:
Code:
static void stopProcess()
{
    System.Console.Write("What process would you like to stop?: ");
    string pname = System.Console.ReadLine().ToUpper();
    Process[] processes = Process.GetProcessesByName(pname);
    Process process = null;

    if( pname == "NONE" )
    {
        System.Console.WriteLine("Process stopper canceled.");
        CommandHandler(commandGiven);
        return;
    }

    string temp;
    foreach (Process p in processes)
    {
        temp = p.ProcessName.ToUpper();

        //if (Convert.ToString(process).ToUpper().Contains(pname.ToUpper()))
        if( temp.IndexOf( pname ) > -1 )
        {
            process = p;
            break;
        }
    }

    if( process != null )
    {
        process.Kill();
        System.Console.WriteLine(process.ProcessName + " has been stopped.");
    }
    else
    {
        System.Console.WriteLine(pname + " is not a valid process name. Please try again.");
        stopProcess();
    }
}
Yay it works now
__________________
Quote:
Originally Posted by Radwen
You should crush your pills and sniff them.
Storm33229 is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5