Using AllowByPassKey

Access97.  I want to deploy a database and prevent users from using the shift key when opening the database.  The AllowByPasskey property will do this.  But I can't figure out how to do it.  The notes I have state:

The AllowByPasskey Property can only be set from code, and should be set to false.  However, a backdoor to the database can be enabled, by using the /cmd option on a command line. for example:

c:\my documents\msaccess.exe test.mdb /cmd AllowShift

The example above, the command line passes the phrase AllowShift to the Access Command() function.  Add code to the application's startup form to check for the special string (AllowShift) in the Command() function and set the AllowByPasskey property to True if the string is found.  A developer can then reopen the unlocked application while holding down the shift, which will provide access to built in menus etc.

How do I do this??

any ideas.  please provide code etc.
thanks
Billy Boy
BillyBoyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rene_moellerConnect With a Mentor Commented:
BillyBoy,

to secure the database do teh following:

Add these functions to a module:

Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
    Dim dbs As Database, prp As Property
    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  'prop not found
        Set prp = dbs.CreateProperty(strPropName, _
          varPropType, varPropValue)
        dbs.Properties.Append prp
        Resume Next
    Else
        'unkown error
        ChangeProperty = False
        Resume Change_Bye
    End If
End Function


Function Init() As Integer
Dim R As Integer
  If UCase$(Command) = "ANY_PARAMETER_YOU_SPECIFY" Then
    R = ChangeProperty("AllowBypassKey", dbBoolean, True)
  Else
    R = ChangeProperty("AllowBypassKey", dbBoolean, False)
  End If
End Function

In your AutoExec macro make sure you call the Init() function

The properties will be set when you open the database, but if the property is changed it will not be active until next time the db is opened.

It looks like you have to specify the full programpath on your commandline if you want to use the /cmd parameter...

"c:\office\access.exe" "c:\data\mydatabase.mdb" /cmd "ANY_PARAMETER_YOU_SPECIFY"

Hope this helps


Rene_Moeller
0
 
coggieCommented:
Hi Billy Boy,

Try this on start up of your application:-

IF UCase$(Command$) = "ALLOWSHIFT" then
   <allowshift = False>
End If

Regards,

Coggie
0
 
SekansCommented:
BillyBoy,
I use this code in VB to dis-allow use of the shift key.  It works for me, if it works for you let me know.

Public Sub TGLLOCK(STATE As String)
On Error GoTo ERRHAND
Dim dbs as Database
Dim NPWD as String
Dim PRP as Property
Set dbs = OpenDatabase("C:\MYDATABASE.MDB", False, False, ";PWD=PASSWORD")
dbs.Properties("ALLOWBYPASSKEY") = FALSE
dbs.Close
End If
ERRHAND:
mess = Left(nname, 12) & " has received the following error: " _
    & Chr(13) & Err.Number & Chr(13) & Err.Description
If Err.Number = 0 Then
    Err.Clear
ElseIf Err.Number = 3031 Then
        Err.Clear
        response = MsgBox("Invalid", 48, "Invalid Password")
    End If
ElseIf Err.Number = 3270 Then
    Set PRP = dbs.CreateProperty("ALLOWBYPASSKEY")
    PRP.Type = dbBoolean
    PRP.Value = FALSE
    dbs.Properties.Append PRP
    Err.Clear
    Resume Next
ElseIf Err.Number = 3343 Then
    response = MsgBox("The database may need to be repaired", 48, "Error")
    End
Else
    MsgBox "An Unexpected Error Has Occurred" & Chr(13) & "Error Number: " & Err.Number _
    & Chr(13) & "Description: " & Err.Description
    Set ACC = Nothing
End If
End Sub

Please let me know if I can help.

Regards,
Sekans
0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
SekansCommented:
If you want, you can leave out all of the error handling code to make it shorter.

Regards,
Sekans
0
 
BillyBoyAuthor Commented:
Thanks for your answer/comments.  I am sure they work well for you but how do I implement them.  Where do I put the code, and how do I ensure that it runs when the database opens.

I need a bit more detail, ie step by step instructions

0
 
BillyBoyAuthor Commented:
Excellent!  works a treat.

However, but only a small however.  Can I avoid using an autoexec macro.  I set myself a goal of never using macros, and even one is too many.  Can I call init() from my splash form,  called frmSplash.  Original aye!  Perhaps I can call it from the form load or open property.  if not, then I can live with autoexec, but if so, then how do I call the init function from elsewhere.

thanks

0
 
BillyBoyAuthor Commented:
Excellent!  works a treat.

However, but only a small however.  Can I avoid using an autoexec macro.  I set myself a goal of never using macros, and even one is too many.  Can I call init() from my splash form,  called frmSplash.  Original aye!  Perhaps I can call it from the form load or open property.  if not, then I can live with autoexec, but if so, then how do I call the init function from elsewhere.

thanks

0
 
TrygveCommented:
How about just trying it and let us know ?
0
 
rene_moellerCommented:
In the Startup forms OnCreate just write ....

Dim R as integer
 R = Init()


thats it.
0
 
rene_moellerCommented:
In the Startup forms OnCreate just write ....

Dim R as integer
 R = Init()


thats it.
0
 
BillyBoyAuthor Commented:
Rene, thanks very much for your help.  an excellent answer.
regards



0
 
TrygveCommented:
This is really interesting. I would like to implement it. But since I am compiling MDE files for my users, I would like to only allow the Command Line "Trojan Horse" for MDB files so that normal user cannot enter. Perhaps an idea ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.