Source code for Issue Number 45

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Just paste this source code into a module called basKeyboard and include it in your project.

'----------------------------------------------------------------------
'
'   Class Name:     basKeyboard
'   Written By:     C&D Programming Corp.
'   Create Date:    2/98
'   Copyright:      Copyright 1998 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'----------------------------------------------------------------------
Option Explicit

'
'   The routines in this module were only tested under Windows 95.  They should work
'   under Windows 95/98/NT.
'

Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" _
        (ByVal uAction As Long, ByVal uParam As Long, _
            ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long


Public Const SPI_SCREENSAVERRUNNING = 97

'
' Disable Crtl+Alt+Del key combination.  This routine works by making Windows think that
' your application is a screen saver.
'
' If an error occurs, this routine will generate an error 5000 (just picked this
' at random).
'
Public Sub DisableCtrlAltDel()
    Dim lRet As Long

    ' If the second parameter is True the Ctrl-Alt-Del keyboard combination will be
    ' disabled since Windows will think a screen saver is running.  If it is False
    ' Ctrl-Alt-Del will behave as normal and show the Close Program dialog box.
    lRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, True, vbNull, 0)
    If lRet <> 0 Then
        Err.Raise 5000, "DisableCtrlAltDel", "Error " & _
                lRet & " occurred while attempting to disable Ctrl-Alt-Del."
    End If
End Sub
'
' Enable Crtl+Alt+Del key combination.   This routine works by making Windows think that
' your application is a screen saver.
'
' If an error occurs, this routine will generate an error 5000 (just picked this
' at random).
'
Public Sub EnableCtrlAltDel()
    Dim lRet As Integer

    ' If the second parameter is True the Ctrl-Alt-Del keyboard combination will be
    ' disabled since Windows will think a screen saver is running.  If it is False
    ' Ctrl-Alt-Del will behave as normal and show the Close Program dialog box.
    lRet = SystemParametersInfo(SPI_SCREENSAVERRUNNING, False, vbNull, 0)
    If lRet <> 0 Then
        Err.Raise 5000, "EnableCtrlAltDel", "Error " & _
                lRet & " occurred while attempting to enable Ctrl-Alt-Del."
    End If
End Sub