Jay1b Posted May 5, 2004 Posted May 5, 2004 Is there a way in which i can close down another application? Say i press a button and notepad exits? Thanks Quote
Arch4ngel Posted May 5, 2004 Posted May 5, 2004 Process[] proc = Process.GetProcesses(); foreach( Process p in proc ) { if( p.ProcessName == "notepad" ) p.Kill(); } Quote "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
akiaz Posted May 5, 2004 Posted May 5, 2004 Will the user be prompted to save any unsaved document using this or does it just close it without saving or prompting? Quote
Arch4ngel Posted May 5, 2004 Posted May 5, 2004 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 Quote "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
Jay1b Posted May 6, 2004 Author Posted May 6, 2004 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'. Quote
Arch4ngel Posted May 6, 2004 Posted May 6, 2004 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. Quote "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 PlausiblyDamp Posted May 6, 2004 Administrators Posted May 6, 2004 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Arch4ngel Posted May 6, 2004 Posted May 6, 2004 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 Quote "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
goodmorningsky Posted May 6, 2004 Posted May 6, 2004 I asked it VB forum..on following link.. but, it works with notepad, however it doesn't work with my custome application.. http://www.visualbasicforum.com/showthread.php?t=158949 I'm posting link any may gets similar idea with C# Quote Sun Certified Web component Developer, Microsoft Certified Solution Developer .NET, Software Engineer
Jay1b Posted May 7, 2004 Author Posted May 7, 2004 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. Quote
Arch4ngel Posted May 7, 2004 Posted May 7, 2004 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. Quote "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
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.