im currently using this code..
using System.Diagnostics;
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.ToLower() == "star")
if (p.ProcessName.ToLower() == "firefox")
p.Kill();
}
}
star and firefox are just examples of the .exe(s) running..
it doesn't quite work when I add another line of "if (p.ProcessName..etc)
also with the firefox line, how can I check for a specific website opened with firefox? ex.. "firefox", "www.google.com" ?
thanks ahead of time.
kill process
Started by ostudioo, Jun 23 2008 01:02 AM
9 replies to this topic
#1
Posted 23 June 2008 - 01:02 AM
|
|
|
#2
Posted 23 June 2008 - 11:44 AM
Your code logic is wrong. What you're saying is this:
If the process is called star, then check if the process is called firefox as well. If so, kill the process.
You see the problem? :)
Consider using a switch statement instead of multiple Ifs.
[highlight=csharp]
switch (p.ProcessName.ToLower())
{
case "star": {}
case "firefox": {}
case "other":
{
p.Kill;
break;
}
}
[/highlight]
If the process is called star, then check if the process is called firefox as well. If so, kill the process.
You see the problem? :)
Consider using a switch statement instead of multiple Ifs.
[highlight=csharp]
switch (p.ProcessName.ToLower())
{
case "star": {}
case "firefox": {}
case "other":
{
p.Kill;
break;
}
}
[/highlight]
#3
Posted 23 June 2008 - 12:10 PM
thanks for the explanation, i understand what i did wrong now. however the code that you gave me doesn't seem to work, i get compile errors.
intellisense is telling "p" doesn't exist.
private void button1_Click(object sender, EventArgs e)
{
switch (p.ProcessName.ToLower())
{
case "firefox": {}
case "star": {}
{
p.Kill;
break;
}
}
}
intellisense is telling "p" doesn't exist.
#4
Posted 23 June 2008 - 01:04 PM
I would use your old code but just use an or in your if statement.
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.ToLower() == "star" || p.ProcessName.ToLower() == "firefox")
p.Kill();
}
that should fix your problem
#5
Posted 23 June 2008 - 01:17 PM
thx, so how would i check if a certain website is running with firefox.
ex: p.ProcessName.ToLower() == "firefox", "www.google.com")
??
ex: p.ProcessName.ToLower() == "firefox", "www.google.com")
??
#7
Posted 24 June 2008 - 10:43 AM
I see.. well can anyone help me with my other question? How to find a certain website is running on firefox..
#8
Posted 24 June 2008 - 11:11 AM
#9
Posted 24 June 2008 - 07:35 PM
can u give an example of the code..?
:confused:
:confused:


Sign In
Create Account


Back to top









