Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Process[] proc = Process.GetProcesses();

 

foreach( Process p in proc )

{

if( p.ProcessName == "notepad" )

p.Kill();

}

 

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted

It's an hard-way.

 

Killing means : Close this apps RIGHT-NOW !

Maybe there's another way of closing it. But... when you close other application... you don't need really to save... unless the context want it so.

 

Tell me if it's enough

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Also, is there a way to log when a process was last active? I would like to create a program that closes any application that has been untouched for 'say 15 mins'.
Posted

Put your thread to verify to each minutes (or seconds).

 

Make a struct :

public struct ProcessLog
{
  Process Proc;
  DateTime Started;
}

 

Make a ProcessLog foreach Process with their start time. And add them to an arraylist. Make sure to keep it updated with process who disapear and those who reappear.

 

My suggestion :

-thread sleep to 1000 miliseconds

-verify each thread if they don't already exists in your arrayList... if they do compare with DateTime.Now ... if it's more than <MAX_TIME_VALUE> then kill it.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

  • Administrators
Posted

That wouldn't meet his requirements though - your method wouldn't identify applications that have been idle for minutes - just things that have been running for minutes.

Personally I'm not sure how you could go about this but if you did you would also need to make sure you didn't also attempt to kill background services, applications minimized to tray etc.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

Hummm ... Idle... maybe by looking to the CPU usage periodicly ?

By having a low cpu usage under a predetermined process... this might give something.

 

But it sure MUST verify that System Process aren't closed (Kill Lsass.exe and you'll get the same result as Sasser) and must "authorize" tray process like Anti-Virus, Sound/Video Special program that come with the retail version of hardware.

 

Unless... he want only one application to watch. Unless of verifing all applications... you could only "register" application that you want to monitor... and when they are ready to be killed... DIIIIE APPLICATION !

 

That's about all... Other idea might come later

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Posted
Cheers guys, i think realistic this would be a much longer project then originally planned. I was thinking about taking note of CPU time and comparing that in cycles, however from examining the task manager a number of programs seem to use 'hey i am still active' when they are idle and this would throw out my idea.
Posted

Ya... of course...

Maybe you could explain us more your problem so that we can help you.

 

Which application do you want to close ? a standard application or one of yours ?

Give us more details and we'll be able to give a hand.

"If someone say : "Die mortal !"... don't stay to see if he isn't." - Unknown

"Learning to program is like going out with a new girl friend. There's always something that wasn't mentioned in the documentation..." - Me

"A drunk girl is like an animal... it scream at everything like a cat and roll in the grass like a dog." - Me after seeing my girlfriend drunk and some of her drunk friend.

C# TO VB TRANSLATOR

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...