Basic Program to Reboot or "Cold" Reboot the Machine (68224)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Cinemania for Windows 1993 edition

This article was previously published under Q68224

SUMMARY

This article describes three ways to reboot your machine from within a Basic program.

WARNING: Be sure to CLOSE all open files before rebooting the computer so as not to lose buffered data.

This information applies to Microsoft QuickBasic versions 4.0, 4.0b, and 4.5; to Microsoft Basic Compiler 6.0 and 6.0b for MS-DOS; and to Microsoft Basic Professional Development System (PDS) 7.0 and 7.1 for MS-DOS.

MORE INFORMATION

Method 1

The first method of rebooting the machine requires only Basic code. This program sends a command directly to the keyboard I/O port using Basic's OUT statement. This causes the keyboard controller chip to reboot the machine just as if you had pressed CTRL+ALT+DEL on the keyboard. Note that this command is supported only on the AT and higher classes of machines. This example will not work on the IBM PC- or XT-class machines or clones.
' REBOOT.BAS
DEFINT A-Z
DEF SEG = &H40      ' If the memory location &H0072:0073 in the BIOS
POKE &H72, &H34     ' data area contains &H1234, then this will cause
POKE &H73, &H12     ' a warm reboot (no self-test or memory
                    ' count). Anything else causes does a cold reboot
                    ' (self-test and memory count).
DEF SEG             ' Return to Basic's default segment.
Command% = &HFE     ' Reset Processor command.
Port% = &H64        ' Keyboard I/O Port
OUT Port%, Command% ' Reboot
				

Method 2

Another way to reboot your machine is to jump directly to the ROM BIOS initialization code (which normally executes automatically when the machine's power is first turned on). This method of rebooting the machine should work on all members of the IBM PC and PS/2 family of computers, as well as the clones of these machines.

To use this method, however, your chosen language must have support for "pointers to functions" as in C or assembly. Because Basic does not support a function pointer data type, you must write a C or assembly procedure to jump to the ROM BIOS boot code. You can call this C or assembly procedure from your Basic program.

Two separate articles in this Knowledge Base describe how to reboot the MS-DOS computer. One article describes using C alone to reboot, and the other article describes using C with inline assembly code to reboot. To see these articles, query on the following words:

reboot and machine and QuickC

For more information about calling C from Basic, query on the word BAS2C. For more information about calling assembly language from Basic, query on the word BAS2MASM.

Method 3

You can also call IBM ROM BIOS interrupt 19 hexadecimal (25 decimal) to reboot the computer. For example:
'Note: To use the Interrupt routine, you must load the Quick library
'QBX.QLB for Basic PDS 7.0 or 7.1 (or QB.QLB for QuickBasic 4.x) using
'the /L switch when you begin QBX.EXE (or QB.EXE for
'QuickBasic 4.x). When you choose the Make EXE File option from the
'Run menu, the environment will then link with QBX.LIB (or QB.LIB).
'
'The following include file must also be present:

'$INCLUDE: 'QBX.BI'
'   but for QuickBasic 4.x, you must instead include 'QB.BI'

DIM regs AS RegType
CALL Interrupt(&H19, regs, regs) 'Reboot the computer
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB68224