Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

Vote on your favorite hash algorithm here!

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-23-2008, 04:02 AM
ostudioo ostudioo is offline
Newbie
 
Join Date: Jun 2008
Posts: 10
Credits: 0
Rep Power: 0
ostudioo is on a distinguished road
Default kill process

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 02:44 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,553
Last Blog:
Web slideshow in JavaS...
Credits: 1,359
Rep Power: 61
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: kill process

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.
csharp Code:
  1. switch (p.ProcessName.ToLower())
  2. {
  3.  case "star": {}
  4.  case "firefox": {}
  5.  case "other":
  6.  {
  7.   p.Kill;
  8.   break;
  9.  }
  10. }
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 03:10 PM
ostudioo ostudioo is offline
Newbie
 
Join Date: Jun 2008
Posts: 10
Credits: 0
Rep Power: 0
ostudioo is on a distinguished road
Default Re: kill process

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.

Code:
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-23-2008, 04:04 PM
gaylo565's Avatar   
gaylo565 gaylo565 is offline
Programmer
 
Join Date: May 2007
Location: flagstaff, az
Posts: 184
Last Blog:
String Manipulation wi...
Credits: 122
Rep Power: 9
gaylo565 is a jewel in the roughgaylo565 is a jewel in the roughgaylo565 is a jewel in the rough
Default Re: kill process

I would use your old code but just use an or in your if statement.
Code:
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.ToLower() == "star" || p.ProcessName.ToLower() == "firefox")

p.Kill();
}
that should fix your problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-23-2008, 04:17 PM
ostudioo ostudioo is offline
Newbie
 
Join Date: Jun 2008
Posts: 10
Credits: 0
Rep Power: 0
ostudioo is on a distinguished road
Default Re: kill process

thx, so how would i check if a certain website is running with firefox.

ex: p.ProcessName.ToLower() == "firefox", "www.google.com")

??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 06-24-2008, 07:17 AM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,553
Last Blog:
Web slideshow in JavaS...
Credits: 1,359
Rep Power: 61
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: kill process

Quote:
Originally Posted by ostudioo View Post
intellisense is telling "p" doesn't exist.
You still need to define p as a Process. I meant just replace the If bit with my code.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-24-2008, 01:43 PM
ostudioo ostudioo is offline
Newbie
 
Join Date: Jun 2008
Posts: 10
Credits: 0
Rep Power: 0
ostudioo is on a distinguished road
Default Re: kill process

I see.. well can anyone help me with my other question? How to find a certain website is running on firefox..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-24-2008, 02:11 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,553
Last Blog:
Web slideshow in JavaS...
Credits: 1,359
Rep Power: 61
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: kill process

If you can get the title of the process (one of p's properties, I suppose), then it usually says the name of the site in the address bar. If not, I'm sure there's an API you could automate.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-24-2008, 10:35 PM
ostudioo ostudioo is offline
Newbie
 
Join Date: Jun 2008
Posts: 10
Credits: 0
Rep Power: 0
ostudioo is on a distinguished road
Default Re: kill process

can u give an example of the code..?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 06-25-2008, 01:48 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: London, England
Posts: 7,553
Last Blog:
Web slideshow in JavaS...
Credits: 1,359
Rep Power: 61
Xav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to beholdXav is a splendid one to behold
Send a message via MSN to Xav
Default Re: kill process

I couldn't be sure. You know when you type "p" and then type a dot? It shows you a list of members. Take a look for a name one.
__________________
[TRUTH] TcM is the best moderator ever! [/TRUTH]
"Valid XHTML is like sex - everybody claims to have the same goal, but everybody has their own tricks and results vary wildly."
Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Process List wazofski Visual Basic Programming 4 06-24-2008 01:55 PM
nice affetcts only pthread or process as a whole? (Linux) mynickmynick C and C++ 0 05-07-2008 12:24 PM
Make a Process undetectable? TcM Software Development Tools 14 12-30-2006 04:24 PM
Chinese kill 50,000 dogs Void The Lounge 12 08-17-2006 03:57 PM
Design Process Dan Website Design 3 07-13-2006 12:11 PM


All times are GMT -5. The time now is 06:39 PM.

Contest Stats

Xav ........ 1359.44
MeTh0Dz|Reb0rn ........ 1072.63
WingedPanther ........ 911.18
marwex89 ........ 906.86
morefood2001 ........ 899.18
John ........ 887.37
Brandon W ........ 770.65
chili5 ........ 312.39
Steve.L ........ 264.99
dcs ........ 232.34

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 83%

Ads