CFanatic

Go Back   CFanatic > Programming > C# Programming

Join CFanatic Forum Now

How to Abort a System SHutdown (system sleep) topic posted under C# Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 06-16-2007, 08:44 AM
Junior Member
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
evarmint is on a distinguished road
| More
How to Abort a System SHutdown (system sleep)

I saw on another thread a way to initiate a shutdown, but I would like to do something a little trickier. How can I detect a shutdown is happening and abort it? Basically, I am trying to disable the sleep key on the keyboard. I've tried overridding the system key handler, but the sleep key still makes it through somehow.
Reply With Quote
  #2  
Old 05-31-2010, 10:36 PM
Junior Member
 
Join Date: May 2010
Location: Vancouver, BC, Canada
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
LynxSI is on a distinguished road
| More
Re: How to Abort a System SHutdown (system sleep)

System level keys are tricky. And to make it trickier the situation you are asking about is handled differently in Windows XP, Vista and 7.

The first thing to try is just to catch your Form_Closing event. Check the event parameter for the CloseReason and set e.Cancel to true when you don't want to shutdown. That will prevent most non-critical shutdowns.

If you want to get really serious, you need to do some "ugly" pinvoke'ing the windows API for Windows hooks. Do some research about "SetWindowsHookEx" with C#. This will allow you to intercept key stroke at a lower level than your project's internal message loop. This one will also work on newer operating systems like Windows Vista and 7.

However, there is one key combination that cannot be overridden in the modern operating systems which is Ctrl+Alt+Delete. This is reserved for operating system security and cannot be intercepted or prevented except via Windows Security Policies.

Best Regards,
- Ben
Reply With Quote
Reply

Thread Tools
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 Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
CFanatic has new Spam prevention system shabbir Announcements 0 10-15-2008 05:46 AM
How to capture the System Cursor Hadah C# Programming 0 04-28-2008 11:10 AM
C# system clock sync xzyfer C# Programming 0 01-14-2008 01:23 AM
Database System missthangythang2003 Looking to hire 0 03-08-2007 11:59 AM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:28 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board