HOWTO: Block CTRL+ALT+DEL and ALT+TAB in Windows 95 in VB

Last reviewed: October 16, 1997
Article ID: Q154868
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 32-bit only, for Windows, version 4.0

SUMMARY

It is possible to prevent the CTRL+ALT+DEL and ALT+TAB key combinations from bringing up the task list in Windows 95 by calling a function in the Win32 API. This article demonstrates this procedure.

NOTE: This is possible only in Windows 95.

MORE INFORMATION

It may be necessary for a program to prevent users from pressing the CTRL+ALT+DEL key combination to bring up the Close Program task list in Windows 95 from where they can end a task or shut down the system.

This can be done using the SystemParametersInfo API. A sample program demonstrating this is given below.

Note that disabling CTRL+ALT+DEL is not recommended because the Close Program dialog was created to allow misbehaving applications to be terminated. If a program "hangs" while CTRL+ALT+DEL is disabled, it may not be possible to terminate it by any method other than a hardware reboot of the machine, possibly resulting in loss of data. Also, this technique may not work in future versions of Windows.

The technique involves tricking Windows 95 into thinking that a screen saver is running. A side effect of this is that CTRL+ALT+DEL no longer has any affect.

The Win32 SDK states:

   "SPI_SCREENSAVERRUNNING Windows 95: Used internally; applications should
   not use this flag. Windows NT: Not supported."

Step-by-Step Example

  1. Start a new Visual Basic project. Form1 is created by default.

  2. Add two Command buttons to Form1.

  3. Put the following code into the General Declarations section of Form1:

       Private Declare Function SystemParametersInfo Lib "user32" _
       Alias "SystemParametersInfoA" (ByVal uAction As Long, _
       ByVal uParam As Long, lpvParam As Any, _
       ByVal fuWinIni As Long) As Long
    
       Private Const SPI_SCREENSAVERRUNNING = 97
    
       Private Sub Command1_Click()
         Dim ret As Integer
         Dim pOld As Boolean
         ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, pOld, 0)
       End Sub
    
       Private Sub Form_Load()
         Command1.Caption = "Disabled"
         Command2.Caption = "Enabled"
       End Sub
    
       Private Sub Command2_Click()
         Dim ret As Integer
         Dim pOld As Boolean
         ret = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, pOld, 0)
       End Sub
    
       Private Sub Form_Unload(Cancel As Integer)
       '  re-enable Ctrl+Alt+Del and Alt+Tab before the program terminates
         Command2_Click
       End Sub
    
    

  4. Run the project and click the Disable button to test. Click the Enable button to enable CTRL+ALT+DEL and ALT+TAB again.

REFERENCES

SystemParametersInfo is documented in the Win32 SDK available in the MSDN/Visual Basic Starter Kit that can be installed from the CD-ROM version of Visual Basic 4.0, Professional and Enterprise Editions. Install by running SETUP.EXE in the MSDN directory on the CD-ROM. It is also available in the MSDN Development Library that is available under subscription from Microsoft.


Additional query words: reboot
Keywords : APrgOther vb432 VB4WIN kbenv kbhowto
Version : 4.0
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.