Thread: Shutdown (again)

  1. #1
    I'm Back
    Join Date
    Dec 2001
    Posts
    556

    Shutdown (again)

    i know , i asked this before but what Bubba said will restart not shutdown form c++ : outp(0x64,0xFE).

    so how can i shutdown from c++

    PS i read the Ralph Brown listing it good but is way over my head.
    -

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    can i, in the dos make a variable and assign it the 'return 0' of c++

    like if the 3 pwd guess are wrong i write return 1 instead of return 0 and do this in the autoexec.bat -->

    ----
    variable answer
    answer=c:\tc\bin\passprog.exe
    if answer==0
    C:\WINDOWS\RUNDLL32.EXE shell32.dll,SHExitWindowsEx 1
    ----

    if yes, what'll be the correct way of doing it...
    -

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    Yes......but your method is windows based anyway....not DOS (SHExitWindowsEx is a Win32 system function....so I guess you need windows up to use it.)

    If you do get Bubba's method to work, and you are in DOS mode, then you may want to lookup the old DOS command "choice"....

    This allows the user to input a choice, and based on the result you can use GOTO statements in your autoexec to brach out to whatever you want to do........

  4. #4
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Hmm... ok
    so whats the dos command for shutdown

    also the question of using CHOICE doesn't arise because the password prog (thats what i want) has to be executed and if the 3 guesses are wrong the program performs shutdown.
    -

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    My method will work from any language as long as the keyboard buffer is not full and you are in pure DOS mode.

    Another way to reboot the computer is to use assembly and do a JMP to address FFFF:0000 which will cause a reboot.

    To do this in C, you could use the emit function which emits bytes into the code stream.

    the following sequence of bytes will force a reboot.


    db 0EAh
    dw 0000h
    dw 0FFFFh

    The 0EAh is the opcode for the JMP instruction.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    In order to force a shutdown, you will have to look up some docs on how to interface with the BIOS. I'm sure the shutdown mechanism is either BIOS related or is done by outputting bytes to certain ports.

  7. #7
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    thanks for the info Bubba

    i'll see what i can get.. or do you know somewhere i can get good info on that??
    -

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No I really don't. Some of that newer stuff is sadly undocumented which makes it hard for small programmers like us to implement very handy features.

    Also, I doubt if it is about outputting to ports since that would seem to be hardware dependent. It is probably a BIOS extension similar to the MS INT 13 extensions for the hard drive and CHS to LBA translation.

    You can try to look in Ralf Brown's interrupt listing as it might be there. I'm sure it is probably within the first 15 interrupts.

  9. #9
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    Ohh man... now i'll have to read the RBIL thing again..
    -

  10. #10
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Just out of interest bubba if i put

    JMP 0xFFFF:0x0

    at the end of my boot sector will it restart???
    VC++ 6

  11. #11
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    ihsir, like Bubba mentioned, there's a few ways of rebooting the computer from any language and any platform. However, shutting down the computer (like Windows can on some computers) is a feature of new BIOS'es. Unfortunately, there is no standard on doing this that I know of. So, until they standardize it, you'll have to support only certain BIOS'es. That's how Windows does it.

  12. #12
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Yeah it works, but im going to have to right a delay function before it will let me desplay a message then restart!
    VC++ 6

  13. #13
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Is there a place or a website where you can find the offsets to JMP to for all the system actions, like shutting down and stuff?

  14. #14
    Registered User VBprogrammer's Avatar
    Join Date
    Mar 2002
    Posts
    175
    Goto Compuboys site http://www.electrichamster.net/Lucie and look under the downloads section you'll find a file called HelpPC.zip (or something like that) this contains many useful files.
    VC++ 6

  15. #15
    Registered User
    Join Date
    Apr 2002
    Posts
    2
    I dont know if this will help you but from within windows the command line

    rundll.exe user.exe,exitwindows

    will shut down the computer. You all probaly all knew this though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Shutdown Pc Timer
    By miranda in forum Windows Programming
    Replies: 10
    Last Post: 12-31-2005, 01:36 AM
  2. startup program deleting shutdown? Need help
    By Miestese in forum Linux Programming
    Replies: 2
    Last Post: 07-06-2005, 09:05 PM
  3. slackware 10 shutdown issue
    By iain in forum Linux Programming
    Replies: 1
    Last Post: 11-24-2004, 07:24 AM
  4. shutdown()
    By Hunter2 in forum Networking/Device Communication
    Replies: 6
    Last Post: 03-18-2004, 07:43 PM
  5. Win98 Won't shutdown...
    By ober in forum Tech Board
    Replies: 5
    Last Post: 03-14-2003, 09:20 AM