Disable Shift Key (1 Viewer)

MadMaxx

.NET foo
Local time
Today, 05:48
Joined
Jun 27, 2003
Messages
138
Because this was brought up in my previous post here is the solution to disable the user from using the shift key to access the database window during startup.

1. Create a new module and past this code inside it:
Code:
'---------------------------------------------------------------------'
' Module: DisableShiftKey                                             '
' Date: July 18, 2003                                                 '
'                                                                     '
' Purpose: To stop the user from holding the shift key on startup to  '
'          access the database window.                                '
'---------------------------------------------------------------------'

Option Compare Database
Option Explicit
'----------------------------------------------------------------------

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
   Dim dbs As Object, prp As Variant
   Const conPropNotFoundError = 3270

   Set dbs = CurrentDb
   On Error GoTo Change_Err
   dbs.Properties(strPropName) = varPropValue
   ChangeProperty = True

Change_Bye:
   Exit Function

Change_Err:
   If Err = conPropNotFoundError Then    ' Property not found.
       Set prp = dbs.CreateProperty(strPropName, _
           varPropType, varPropValue)
       dbs.Properties.Append prp
       Resume Next
   Else
       ' Unknown error.
       ChangeProperty = False
       Resume Change_Bye
   End If
End Function
'----------------------------------------------------------------------

Function BypassKey(onoff As Boolean)
   Const DB_Boolean As Long = 1
   ChangeProperty "AllowBypassKey", DB_Boolean, onoff
End Function
'-----------------------------------------------------------------------

Then save the module to whatever you like.

2. Create the macros.
2.1 Macro Name: ByPassKeyOff
Action: Runcode
Function: BypassKey(False)
2.2 Macro Name: ByPassKeyOn
Action: Runcode
Function: BypassKey(True)

3. On your switchboard or logon screen create a rectangle with the same backcolor as the form and no border. Remember where it is. Or if you have a picture you can use it aswell. On the properties of the rectangle or picture select the Event tab->OnClick. Use the picker to select the ByPassKeyOn macro.

4. Run the ByPassKeyOff macro. Save and close the db.

5 Now when you start up and hold the shift key the db window will not show. To allow the shift key click where you put your rectangle or click the picture and close the db. Re-open with the shift key and the database window will appear. To disable do step 4.

There you go. Just another way to make sure your database is secure.

cheers from MadMaxx
 

IgorB

Registered User.
Local time
Today, 10:48
Joined
Jun 4, 2003
Messages
183
That was easy, funciton presents in one of the MS Access book.

Now show me a function which allow to restore Shift(Bypass) key for "secured" database running from external another database!!!

Cheers.
 

IMO

Now Known as ___
Local time
Today, 10:48
Joined
Sep 11, 2002
Messages
723
There have been several examples posted here, do a search for 'enable/disable shiftkey'

IMO
 

ghudson

Registered User.
Local time
Today, 05:48
Joined
Jun 8, 2002
Messages
6,195
IgorB, you can still disable/enable the shift key from within the secured db. The
db will have to be closed and reopened to be able to open the db using the shift key.

The below function and command button code will allow you to use a password
protected input box to determine if the Shift key can be disabled or not.

You might have to set your "References" to DAO 3.6. When you are viewing
the module, click the Tools menu >>> References >>> and Browse for Microsoft
DAO 3.6 >>> Select "Files of type: Executable Files (*.exe; *.dll)"
My DLL was located @ C:\Program Files\Common Files\Microsoft Shared\DAO.

Copy this function into a new public module.
Code:
Public Function SetProperties(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
On Error GoTo Err_SetProperties
    
    'Dim db As Database, prp As Property
    Dim db As DAO.Database, prp As DAO.Property
    
    Set db = CurrentDb
    db.Properties(strPropName) = varPropValue
    SetProperties = True
    Set db = Nothing
    
Exit_SetProperties:
    Exit Function
    
Err_SetProperties:
    If Err = 3270 Then 'Property not found
        Set prp = db.CreateProperty(strPropName, varPropType, varPropValue)
        db.Properties.Append prp
        Resume Next
    Else
        SetProperties = False
        MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf & Err.Description
        Resume Exit_SetProperties
    End If
    
End Function
Assign this to the OnClick event of a command (transparent?) button named "bDisableBypassKey".
Change the "TypeYourPasswordHere" default password.
This sub ensures the user is the programmer needing to disable the Bypass Key.
You can not format an Input Box!
Code:
Private Sub bDisableBypassKey_Click()
On Error GoTo Err_bDisableBypassKey_Click
    
    Dim strInput As String
    Dim strMsg As String
    
    Beep
    strMsg = "Do you want to enable the Bypass Key?" & vbCrLf & vbLf & "Please key the programmer's password to enable the Bypass Key."
    strInput = InputBox(Prompt:=strMsg, Title:="Disable Bypass Key Password")
    
    If strInput = "TypeYourPasswordHere" Then
        SetProperties "AllowBypassKey", dbBoolean, True
        Beep
        MsgBox "The Bypass Key has been enabled." & vbCrLf & vbLf & "The Shift key will allow the users to bypass the startup options the next time the database is opened.", vbInformation, "Set Startup Properties"
    Else
        Beep
        SetProperties "AllowBypassKey", dbBoolean, False
        MsgBox "Incorrect ''AllowBypassKey'' Password!" & vbCrLf & vbLf & "The Bypass Key was disabled." & vbCrLf & vbLf & "The Shift key will NOT allow the users to bypass the startup options the next time the database is opened.", vbCritical, "Invalid Password"
        Exit Sub
    End If
    
Exit_bDisableBypassKey_Click:
    Exit Sub
    
Err_bDisableBypassKey_Click:
    MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf & Err.Description
    Resume Exit_bDisableBypassKey_Click
    
End Sub
HTH
 

Kevin_S

Registered User.
Local time
Today, 05:48
Joined
Apr 3, 2002
Messages
635
ghudson -

First let me say that I think your code to disable/enable the shift bypass is the cleanest and most polished I have seen to date - my hats off to you for being willing and gracious enough to post it for others to use.

Having said that - have you thought about included code to handle the action of the user when they select 'Cancel' on the input box? Currently if you click the command button to bring up the input box and the user decides not to enter anything in the input box and simply choose the cancel option to exit the input the code interprets this as the user is entering (null) as the password and displays the 'Invalid Password' message and disables the shift bypass.

Just food for thought - not in any way trying to criticise your work/code...:)

Kevin
 

ghudson

Registered User.
Local time
Today, 05:48
Joined
Jun 8, 2002
Messages
6,195
Kevin_S,

I did not want to trap for the Cancel button for I felt that only the programmer should be using this function. If someone else stumbled upon the function or tried to be cute, I wanted to force the db to not allow the Shift key just incase it was disabled. I actually assign the code to the double click event of graphic to make it as difficult as possible for somebody to stumble upon the function.

Thanks for the feedback. :)
 

Kevin_S

Registered User.
Local time
Today, 05:48
Joined
Apr 3, 2002
Messages
635
Good point! :D

In a way you did trap for the cancel button - by making the result lock the db in case a wandering gremlin got lucky!!!

Like I said - Great Code - just trying to help!!!

Take Care,
Kevin
 

jon98548

Registered User.
Local time
Today, 05:48
Joined
Feb 14, 2003
Messages
141
Hayley, I downloaded your sample and it works great. I was wondering though if I am disabling a database on a server and some one else gets your sample also, could they enable it? Would the code ghudson shows avoid that problem?
 

Treason

#@$%#!
Local time
Today, 05:48
Joined
Mar 12, 2002
Messages
340
cant format the input box

GHudson, again great coding... Of Course you are aware of the fact that you cannot format the inputbox, so the admin password is plainly visible.

Well I was trying to work out another solution for this password problem as my fourteen year old nephew was watching. He thinks it would be a great idea to assign the password to be ****** :D . Which gave us all a good laugh!

now if I could only mimic myself pressing other key combinations....

Just thought I would share that, lol

:p
 

hi there

Registered User.
Local time
Today, 05:48
Joined
Sep 5, 2002
Messages
171
I just ran across this code. wow! this is great code. very clear and effective. excellent work GHudson. thanks for sharing.
 

pat_nospam

Registered User.
Local time
Today, 10:48
Joined
Oct 14, 2003
Messages
151
Great code ghudson!

Thanks for the assist,

Pat
 
Last edited:

cross5900

Blarg!
Local time
Today, 04:48
Joined
Mar 24, 2006
Messages
92
we actually have a standalone dbase that allows you to browse for the mde/mdb you are needing to disable/enable shift and f11 (all the special dev keys)... it is pretty handy.
 

Hayley Baxter

Registered User.
Local time
Today, 10:48
Joined
Dec 11, 2001
Messages
1,607
ghudson said:
Ricky Hicks gets the credit for designing the sample that Hayley posted at that thread! That version is very outdated and you can get the latest version @ ByPass Shift Key Utility for Access

Hello Ghudson

Thanks for posting the updated version of the shift bypass key, it looks very useful.

I also wanted to point out that I didn't mean to steal the credit for posting that sample designed by Ricky Hicks, that is something I would never do. I am not suggesting that's what you were saying. I just wanted to apologise if it came across that way.

Best Regards

Hayley
 

hooks

Registered User.
Local time
Today, 02:48
Joined
Aug 13, 2004
Messages
160
Treason said:
GHudson, again great coding... Of Course you are aware of the fact that you cannot format the inputbox, so the admin password is plainly visible.



:p
You can format the inputbox with a module. Its a lot of code but it works great.

Here is the code

Code:
'////////////////////////////////////////////////////////////////////
'Password masked inputbox
'Allows you to hide characters entered in a VBA Inputbox.
'
'Code written by Daniel Klann
'http://www.danielklann.com/
'March 2003

'// Kindly permitted to be amended
'// Amended by Ivan F Moala
'// http://www.xcelfiles.com
'// April 2003
'// Works for Xl2000+ due the AddressOf Operator
'////////////////////////////////////////////////////////////////////

'********************   CALL FROM FORM *********************************
'    Dim pwd As String
'
'    pwd = InputBoxDK("Please Enter Password Below!", "Database Administration Security Form.")
'
'    'If no password was entered.
'    If pwd = "" Then
'        MsgBox "You didn't enter a password!  You must enter password to 'enter the Administration Screen!" _
'        , vbInformation, "Security Warning"
'    End If
'**************************************



'API functions to be used
Private Declare Function CallNextHookEx _
    Lib "user32" ( _
    ByVal hHook As Long, _
    ByVal ncode As Long, _
    ByVal wParam As Long, _
    lParam As Any) _
As Long

Private Declare Function GetModuleHandle _
    Lib "kernel32" _
    Alias "GetModuleHandleA" ( _
    ByVal lpModuleName As String) _
As Long

Private Declare Function SetWindowsHookEx _
    Lib "user32" _
    Alias "SetWindowsHookExA" ( _
    ByVal idHook As Long, _
    ByVal lpfn As Long, _
    ByVal hmod As Long, _
    ByVal dwThreadId As Long) _
As Long

Private Declare Function UnhookWindowsHookEx _
    Lib "user32" ( _
    ByVal hHook As Long) _
As Long

Private Declare Function SendDlgItemMessage _
    Lib "user32" Alias "SendDlgItemMessageA" ( _
    ByVal hDlg As Long, _
    ByVal nIDDlgItem As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) _
As Long

Private Declare Function GetClassName _
    Lib "user32" _
    Alias "GetClassNameA" ( _
    ByVal hWnd As Long, _
    ByVal lpClassName As String, _
    ByVal nMaxCount As Long) _
As Long

Private Declare Function GetCurrentThreadId _
    Lib "kernel32" () _
As Long

'Constants to be used in our API functions
Private Const EM_SETPASSWORDCHAR = &HCC
Private Const WH_CBT = 5
Private Const HCBT_ACTIVATE = 5
Private Const HC_ACTION = 0

Private hHook As Long

Public Function NewProc(ByVal lngCode As Long, _
                        ByVal wParam As Long, _
                        ByVal lParam As Long) As Long

Dim RetVal
Dim strClassName As String, lngBuffer As Long

If lngCode < HC_ACTION Then
    NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
    Exit Function
End If

strClassName = String$(256, " ")
lngBuffer = 255

If lngCode = HCBT_ACTIVATE Then    'A window has been activated
    RetVal = GetClassName(wParam, strClassName, lngBuffer)
    If Left$(strClassName, RetVal) = "#32770" Then  'Class name of the Inputbox
        'This changes the edit control so that it display the password character *.
        'You can change the Asc("*") as you please.
        SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
    End If
End If
    
'This line will ensure that any other hooks that may be in place are
'called correctly.
CallNextHookEx hHook, lngCode, wParam, lParam

End Function

'// Make it public = avail to ALL Modules
'// Lets simulate the VBA Input Function
Public Function InputBoxDK(Prompt As String, Optional Title As String, _
            Optional Default As String, _
            Optional Xpos As Long, _
            Optional Ypos As Long, _
            Optional Helpfile As String, _
            Optional Context As Long) As String
    
Dim lngModHwnd As Long, lngThreadID As Long
    
'// Lets handle any Errors JIC! due to HookProc> App hang!
On Error GoTo ExitProperly
lngThreadID = GetCurrentThreadId
lngModHwnd = GetModuleHandle(vbNullString)
    
hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
If Xpos Then
    InputBoxDK = InputBox(Prompt, Title, Default, Xpos, Ypos, Helpfile, Context)
Else
    InputBoxDK = InputBox(Prompt, Title, Default, , , Helpfile, Context)
End If

ExitProperly:
UnhookWindowsHookEx hHook

End Function

Sub TestDKInputBox()
Dim x

x = InputBoxDK("Type your password here.", "Password Required")
If x = "" Then End
If x <> "yourpassword" Then
    MsgBox "You didn't enter a correct password."
    End
End If

MsgBox "Welcome Creator!", vbExclamation
    
End Sub
 

halem2

Registered User.
Local time
Today, 05:48
Joined
Nov 8, 2006
Messages
180
ghudson

First: awesome! I have used it in other db's and it rocks!

Question: I'm trying to use it in a new db but it is not hiding the db even when the password entered is wrong. I have not selected tools\startup\display db window. I also ensured I have DAO 6.0 in the references...

What else can I look at?

thanks a million.:)
 
Last edited:

Users who are viewing this thread

Top Bottom