Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
I want to stop shut down until my C#.net windows app is running.That is even when
user shutdowns pc i need code that abort this shutdown
Posted 24-Feb-13 17:17pm
fdiu498
Comments
Sergey Alexandrovich Kryukov at 24-Feb-13 22:45pm
   
Abort shutdown and delay shutdown until your application is running are different things. You can do first, but an attempt to do the second is useless.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't. There are so many ways a user can force your app to be terminated it's silly.
 
You're kidding yourself if you think you can. It's like believing you can protect images being copied off websites - it's impossible.
 
Sorry, but users will kill your app one way or another (eg. power off). The question is how you nicely handle the shutdown.
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 24-Feb-13 23:06pm
   
Agree, my 5, with one clarification: it's of course possible to abort previously initiated shutdown, but... I don't even want to discuss using it for preventing of the shutdown until some application is running, bad idea. Please see my answer.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please see my comment to the question.
 
You can abort initiated shutdown using the command "shutdown /a". So, programmatically,
System.Diagnostics.Process.Start("shutdown", "/a");
 
But it cannot help you to keep the system working until your application is executed. The whole idea is wrong; and the author of the Solution 1 is right.
 
—SA
  Permalink  
Comments
fdiu at 24-Feb-13 23:27pm
   
i do this but error like the application was unable to start currectly click ok to close
Sergey Alexandrovich Kryukov at 24-Feb-13 23:31pm
   
Did you run it under debugger? Could be too many reasons for that.
But I answered not for you to apply this method. The whole idea is wrong. See Solution 1.
—SA
fdiu at 25-Feb-13 6:59am
   
sorry for late because of electricity problem.
I got that we can not delay shutdown but can abort .I write code like in forms closing event handler i check the cause ,if it is due to windows shutdown then i want to abort it
Sergey Alexandrovich Kryukov at 25-Feb-13 11:55am
   
I already answered.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 320
1 OriginalGriff 155
2 Peter Leow 115
3 Afzaal Ahmad Zeeshan 114
4 deepakdynamite 110
0 OriginalGriff 7,510
1 DamithSL 5,519
2 Sergey Alexandrovich Kryukov 5,044
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 24 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100