Click here to Skip to main content
11,704,509 members (61,250 online)
Click here to Skip to main content

A simple utility for shutting down your System

, 28 Mar 2003 CPOL 85.8K 682 31
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Balkrishna Talele
Architect
India India
Computer Engineer. Pune univ.

You may also be interested in...

Comments and Discussions

 
Generalshutdown -i Pin
Vasudevan Deepak Kumar17-Aug-07 4:42
memberVasudevan Deepak Kumar17-Aug-07 4:42 
GeneralError "A required privilege is not held by the client" Pin
GDoubleD2-Apr-03 5:02
memberGDoubleD2-Apr-03 5:02 
GeneralRe: Error "A required privilege is not held by the client" Pin
Balkrishna Talele8-Apr-03 9:39
memberBalkrishna Talele8-Apr-03 9:39 
GeneralRe: Error "A required privilege is not held by the client" Pin
beastonabun15-Apr-03 8:34
memberbeastonabun15-Apr-03 8:34 
GeneralRe: Error "A required privilege is not held by the client" Pin
Anonymous18-Apr-03 7:04
sussAnonymous18-Apr-03 7:04 
GeneralRe: Error "A required privilege is not held by the client" Pin
GDoubleD24-Apr-03 5:13
memberGDoubleD24-Apr-03 5:13 
GeneralRe: Error &quot;A required privilege is not held by the client&quot; Pin
fato28-Aug-03 0:42
memberfato28-Aug-03 0:42 
GeneralWhen are you... Pin
Rickard Andersson29-Mar-03 10:12
memberRickard Andersson29-Mar-03 10:12 
GeneralRe: When are you... Pin
mwilliamson29-Mar-03 11:22
membermwilliamson29-Mar-03 11:22 
GeneralRe: When are you... Pin
Rickard Andersson30-Mar-03 5:48
memberRickard Andersson30-Mar-03 5:48 
GeneralRe: When are you... Pin
Alexander Wiseman30-Mar-03 10:16
memberAlexander Wiseman30-Mar-03 10:16 
GeneralRe: When are you... Pin
Andreas Saurwein30-Mar-03 22:35
memberAndreas Saurwein30-Mar-03 22:35 
GeneralRe: When are you... Pin
Gareth Maguire18-Mar-04 5:49
memberGareth Maguire18-Mar-04 5:49 
GeneralRe: When are you... Pin
Gareth Maguire18-Mar-04 5:51
memberGareth Maguire18-Mar-04 5:51 
GeneralRe: When are you... Pin
Vasudevan Deepak Kumar17-Aug-07 4:44
memberVasudevan Deepak Kumar17-Aug-07 4:44 
GeneralRe: When are you... Pin
Balkrishna Talele30-Mar-03 7:20
memberBalkrishna Talele30-Mar-03 7:20 
GeneralRe: When are you... Pin
Rickard Andersson30-Mar-03 20:23
memberRickard Andersson30-Mar-03 20:23 
GeneralRe: When are you... Pin
Balkrishna Talele31-Mar-03 5:31
sussBalkrishna Talele31-Mar-03 5:31 
GeneralRe: When are you... Pin
Rickard Andersson1-Apr-03 7:42
memberRickard Andersson1-Apr-03 7:42 

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.

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