Click here to Skip to main content
Licence CPOL
First Posted 28 Mar 2003
Views 79,197
Bookmarked 31 times

A simple utility for shutting down your System

By | 28 Mar 2003 | Article
Simply set the time on the tool for the machine you wish to shut down (24 hrs), choose whether to log off, reboot or shutdown, or power off (ATX main boards only), and click Hide. It has been tested on Win9x/ME, WinNT/2000/XP.

Introduction

This is a simple utility for shutting down your system.

Simply set the time on the tool, for the machine you wish to shut down (24 hrs), choose whether to log off, reboot or shutdown, or power off (ATX main boards only), and click Hide. It has been tested on Win9x/ME, WinNT/2000/XP. The full source code is in the Zip file.

In case of problems in getting it to work, when setting the end time make sure that you click on the number after that. It is a list box, so the GetCaretIndex() call will always return 0 unless you select a number by clicking on it.

What's new in this tool?

  1. Well, old wine in a new bottle. The nasty code in OnInitDialog() is totally replaced by a new one. Now some of my colleagues will neither get totally shutdown by looking at that code ;-D nor will it look nasty!!!.
  2. Dialog refreshing is toggled by the flag, so that it doesn't get unnecessarily repainted (when clicked on menu "Open main window").
  3. Ability to abort shutdown in progress through message box.

What is really missing?

  • The ability to shut down remote computers.

I don't have network here. But if you want to remotely shutdown the computer use the following function: BOOL InitiateSystemShutdown. It has the following parameters:

  1. pointer to the name of the computer to be shutdown,
  2. pointer to the message to be displayed in the dialog box,
  3. time to display the dialog box,
  4. force applications closed flag,
  5. reboot flag.

The first parameter takes the name of the computer in the network. If it's null the local machine will be down.

Working

As soon as you run/compile, it will be passed to the system tray. OnInitDialog() will fill the list box with hrs/mins/secs as follows:

CListBox* pListHrs = static_cast(GetDlgItem(IDC_LISTHRS));
while(i<=24) { _itoa(i,buff,10); pListHrs->AddString(buff); i++;}

Timer will start its execution and the user's time will be checked at regular intervals. As soon as the condition is met, the selected option will be passed to Sflag. This flag in turn is checked in the switch statement and the following code executes:

Switch(Sflag) {
    case 0: CDialog::KillTimer (nIDEvent); 
            ExitWindowsEx(EWX_SHUTDOWN ,EWX_FORCE);
            exit(0);
            break; 
    .
    .
    .
}

If you have recent versions of Visual Studio and MSDN (which, I don't have), you can simply add hibernate. You can use EWX_FORCEIFHUNG instead of EWX_FORCE, sometimes for Windows NT 5.0 and later: it forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message. This flag is ignored if EWX_FORCE is used.

Credits

As far as the different classes that are used in my utility, appropriate credits are given to:

  • CHoverButton by Niek Albers.
  • Auto Font by Keith Rule.
  • System Tray by Chris Maunder.
  • On line MSDN by Microsoft.

tray.cpp and tray.h were originally named as systemtray.cpp and systemtray.h at CodeProject. All the above class files were downloaded from CodeProject. Thanks to all those who helped me directly or indirectly for this (and other utilities). Special thanks to all those people who maintain CodeProject.

License

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

About the Author

Balkrishna Talele

Architect

India India

Member

Computer Engineer. Pune univ.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalshutdown -i PinmemberVasudevan Deepak Kumar4:42 17 Aug '07  
GeneralError "A required privilege is not held by the client" PinmemberGDoubleD5:02 2 Apr '03  
GeneralRe: Error "A required privilege is not held by the client" PinmemberBalkrishna Talele9:39 8 Apr '03  
GeneralRe: Error "A required privilege is not held by the client" Pinmemberbeastonabun8:34 15 Apr '03  
GeneralRe: Error "A required privilege is not held by the client" PinsussAnonymous7:04 18 Apr '03  
GeneralRe: Error "A required privilege is not held by the client" PinmemberGDoubleD5:13 24 Apr '03  
GeneralRe: Error "A required privilege is not held by the client" Pinmemberfato0:42 28 Aug '03  
GeneralWhen are you... PinmemberRickard Andersson10:12 29 Mar '03  
GeneralRe: When are you... Pinmembermwilliamson11:22 29 Mar '03  
GeneralRe: When are you... PinmemberRickard Andersson5:48 30 Mar '03  
GeneralRe: When are you... PinmemberAlexander Wiseman10:16 30 Mar '03  
GeneralRe: When are you... PinmemberAndreas Saurwein22:35 30 Mar '03  
GeneralRe: When are you... PinmemberGareth Maguire5:49 18 Mar '04  
GeneralRe: When are you... PinmemberGareth Maguire5:51 18 Mar '04  
GeneralRe: When are you... PinmemberVasudevan Deepak Kumar4:44 17 Aug '07  
GeneralRe: When are you... PinmemberBalkrishna Talele7:20 30 Mar '03  
GeneralRe: When are you... PinmemberRickard Andersson20:23 30 Mar '03  
GeneralRe: When are you... PinsussBalkrishna Talele5:31 31 Mar '03  
GeneralRe: When are you... PinmemberRickard Andersson7:42 1 Apr '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 29 Mar 2003
Article Copyright 2003 by Balkrishna Talele
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid