Thread: How to shutdown a computer?

  1. #1
    Digga
    Join Date
    May 2005
    Location
    Colorado
    Posts
    15

    How to shutdown a computer?

    I am a beginner programmer. I would like to make a windows program that will shut down the computer. First the user double clicks on the application and a dialog box pops up saying that windows will shutdown. The user clicks ok and the computer then shutsdown immediately. I have made a dos program that does this. But when I try to do the same thing for a windows application, I only get the dialog box and a dos prompt pops up real quick and goes away. Here is the key figure of my code responsible for shuting the computer:
    system("Shutdown -s -t00"); Any way maybe you could help me fiqure out how to do this.

    Thanx,
    Digga

  2. #2
    Chief Code Coloniser!
    Join Date
    Apr 2005
    Posts
    121
    Use the ExitWindowsEx API function.

  3. #3
    Digga
    Join Date
    May 2005
    Location
    Colorado
    Posts
    15

    Still no shutdown

    I understand the function. But what do I put for the reason of shutdown as the second parameter. Even if I put down any old thing I get a comple error that it is undeclared. I need the reason.h library. So how would I get this library? I've tried putting in zero (unplanned shutdown), and that works. But it does not shutdown. However, I can create a program that automatically logs off. In the mean time I'm going to experiment with InitiateSystemShutdown();

    Digga

  4. #4
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    I hope you have a very good reason for being a beginner program and wanting to write a program that shuts down a computer, this thing has some kind of nasty odor.

  5. #5
    Digga
    Join Date
    May 2005
    Location
    Colorado
    Posts
    15
    Well I can do the basic like make a window and also make a dialog box. But I'm more interested in making the computer shutdown or print something or delete a file(s). I'm just woundering! I'm going to learn all about prgramming sooner or later, so why not learn the things that interest me. So can anyone help me on this? Please!

  6. #6
    Digga
    Join Date
    May 2005
    Location
    Colorado
    Posts
    15
    Well I tried the InitiateSystemShutdown(); function and i get a compile error: Undefined reference to 'nitiateSystemShutdown' So I found out that it requires Winreg.h. So I took I look at that and everthing is there, but it includes macwin32.h. But I search and this library is missing! That would most likely explain why I got a reference error when I compiled it. So how to I find this library, or maybe I need a new compiler or someting! :-0

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Nah, ain't missing. But you didn't specify an import library: look at the documentation again and look for a .lib file that is required. Add that to the "additional libraries" in the Input section of the Linker settings in the project properties.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Digga
    Join Date
    May 2005
    Location
    Colorado
    Posts
    15
    Oh I see. I took a look at the documentation and I need Advapi32.lib. That makes sense now. But how do I get this lib if I don't have it. Then where do I put it and how do I link it. I've just simply never done this before.
    Last edited by Digga; 05-03-2005 at 01:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 34
    Last Post: 02-26-2006, 01:16 PM
  2. Major Computer Problem
    By Olidivera in forum Tech Board
    Replies: 10
    Last Post: 07-15-2005, 11:15 AM
  3. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  4. Computer will not boot.
    By RealityFusion in forum Tech Board
    Replies: 25
    Last Post: 09-10-2004, 04:05 PM
  5. Shutdown computer
    By Kinasz in forum Tech Board
    Replies: 2
    Last Post: 03-17-2003, 12:55 AM