DB to work only with machine name

syedadnan

Access Lover
Local time
Today, 15:42
Joined
Mar 27, 2013
Messages
315
Regards

I want to know how to make this that i have a DB and want to make it in this way that if someone copy it and paste at new system (PC) then it do not work as internally it should be specified with user/machine name in user table in this way i want to restrict copy of the DB unless authorised
 
Regards

I want to know how to make this that i have a DB and want to make it in this way that if someone copy it and paste at new system (PC) then it do not work as internally it should be specified with user/machine name in user table in this way i want to restrict copy of the DB unless authorised
I'm not sure that using an Access table would be very secure. Just a thought, but how would a user first get entered into the table.
 
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.

Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.

Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.

  1. Find out your own machine name.
    Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
    • Click on Start Menu.
    • Type cmd in the 'Search Program and files' control and press Enter.
    • Type Set in the DOS prompt window.
      You will find the Environment setting listed on the window.
    • Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
      USER-PC is my machine's name given as an example.
    • Note down your machine name and then type Exit to close the DOS command window.
  2. Open Access and create a new Database.
  3. Press ALT+F11 to open the VBA Window.
  4. Select Module from Insert menu and create a new Module.
  5. Copy and Paste the following Code into the Module:
    Code:
    Function SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
        CheckMachine
    End Function
    
    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
    
    Public Function CheckMachine()
    Dim strMachine As String
    strMachine = Environ("COMPUTERNAME")
    
    If strMachine = "USER-PC" Then
        'MsgBox "Authorized"
    Else
        MsgBox "Not Authorized"
        DoCmd.Quit
    End If
    
    End Function
  6. Replace USER-PC in the Code with your own machine name.
    NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
  7. Select databasename Properties (like db3 Properties) from Tools Menu.
  8. Select Protection Tab.
  9. Put check mark in the Lock Project from Viewing
  10. Put a password and verify it in the second control.
    Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
  11. Click OK to save and close the control.
  12. Open a new macro and select RunCode in the Action column.
  13. Type SetBypassProperty() in the Function Name argument.
  14. Save the Macro with the name Autoexec
  15. Save and Close the Database.
  16. Open the database and check whether the database is opening normally on your Machine.
  17. Make a copy of the database and take it to another machine and try opening it on that machine.
 
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.

Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.

Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.

  1. Find out your own machine name.
    Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
    • Click on Start Menu.
    • Type cmd in the 'Search Program and files' control and press Enter.
    • Type Set in the DOS prompt window.
      You will find the Environment setting listed on the window.
    • Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
      USER-PC is my machine's name given as an example.
    • Note down your machine name and then type Exit to close the DOS command window.
  2. Open Access and create a new Database.
  3. Press ALT+F11 to open the VBA Window.
  4. Select Module from Insert menu and create a new Module.
  5. Copy and Paste the following Code into the Module:
    Code:
    Function SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
        CheckMachine
    End Function
    
    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
    
    Public Function CheckMachine()
    Dim strMachine As String
    strMachine = Environ("COMPUTERNAME")
    
    If strMachine = "USER-PC" Then
        'MsgBox "Authorized"
    Else
        MsgBox "Not Authorized"
        DoCmd.Quit
    End If
    
    End Function
  6. Replace USER-PC in the Code with your own machine name.
    NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
  7. Select databasename Properties (like db3 Properties) from Tools Menu.
  8. Select Protection Tab.
  9. Put check mark in the Lock Project from Viewing
  10. Put a password and verify it in the second control.
    Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
  11. Click OK to save and close the control.
  12. Open a new macro and select RunCode in the Action column.
  13. Type SetBypassProperty() in the Function Name argument.
  14. Save the Macro with the name Autoexec
  15. Save and Close the Database.
  16. Open the database and check whether the database is opening normally on your Machine.
  17. Make a copy of the database and take it to another machine and try opening it on that machine.



Thanks a lot marvelous work for me.. just if you can do a favor if you can provide me a sample DB for it
 
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.

Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.

Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.

  1. Find out your own machine name.
    Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
    • Click on Start Menu.
    • Type cmd in the 'Search Program and files' control and press Enter.
    • Type Set in the DOS prompt window.
      You will find the Environment setting listed on the window.
    • Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
      USER-PC is my machine's name given as an example.
    • Note down your machine name and then type Exit to close the DOS command window.
  2. Open Access and create a new Database.
  3. Press ALT+F11 to open the VBA Window.
  4. Select Module from Insert menu and create a new Module.
  5. Copy and Paste the following Code into the Module:
    Code:
    Function SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
        CheckMachine
    End Function
    
    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
    
    Public Function CheckMachine()
    Dim strMachine As String
    strMachine = Environ("COMPUTERNAME")
    
    If strMachine = "USER-PC" Then
        'MsgBox "Authorized"
    Else
        MsgBox "Not Authorized"
        DoCmd.Quit
    End If
    
    End Function
  6. Replace USER-PC in the Code with your own machine name.
    NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
  7. Select databasename Properties (like db3 Properties) from Tools Menu.
  8. Select Protection Tab.
  9. Put check mark in the Lock Project from Viewing
  10. Put a password and verify it in the second control.
    Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
  11. Click OK to save and close the control.
  12. Open a new macro and select RunCode in the Action column.
  13. Type SetBypassProperty() in the Function Name argument.
  14. Save the Macro with the name Autoexec
  15. Save and Close the Database.
  16. Open the database and check whether the database is opening normally on your Machine.
  17. Make a copy of the database and take it to another machine and try opening it on that machine.


Great support really.. thank you very much..

As far as module as concern it is clear to me but how to locate it as you mentioned in the quote but i ma not finding the fields you mentioned kindly if you brief in details that how to locate this module and the fields as me not very much famiiliar with the fields
 
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.

Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.

Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.

  1. Find out your own machine name.
    Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
    • Click on Start Menu.
    • Type cmd in the 'Search Program and files' control and press Enter.
    • Type Set in the DOS prompt window.
      You will find the Environment setting listed on the window.
    • Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
      USER-PC is my machine's name given as an example.
    • Note down your machine name and then type Exit to close the DOS command window.
  2. Open Access and create a new Database.
  3. Press ALT+F11 to open the VBA Window.
  4. Select Module from Insert menu and create a new Module.
  5. Copy and Paste the following Code into the Module:
    Code:
    Function SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
        CheckMachine
    End Function
    
    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
    
    Public Function CheckMachine()
    Dim strMachine As String
    strMachine = Environ("COMPUTERNAME")
    
    If strMachine = "USER-PC" Then
        'MsgBox "Authorized"
    Else
        MsgBox "Not Authorized"
        DoCmd.Quit
    End If
    
    End Function
  6. Replace USER-PC in the Code with your own machine name.
    NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
  7. Select databasename Properties (like db3 Properties) from Tools Menu.
  8. Select Protection Tab.
  9. Put check mark in the Lock Project from Viewing
  10. Put a password and verify it in the second control.
    Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
  11. Click OK to save and close the control.
  12. Open a new macro and select RunCode in the Action column.
  13. Type SetBypassProperty() in the Function Name argument.
  14. Save the Macro with the name Autoexec
  15. Save and Close the Database.
  16. Open the database and check whether the database is opening normally on your Machine.
  17. Make a copy of the database and take it to another machine and try opening it on that machine.

I have done as instructed but even after changing the user-pc by my machine name then other name which is not my machine name the db still opening and not closing it self, when i double click autoexe macro it saying not authorized and when i click module then it is asking for password i thin these things are working fine but there might be some other error
 
Database with Code is attached.

Bunch of Thanks for the sample and your time.. please advise how to open the file as currently is opening with a message saying not authorised and closing thereafter.. i know it is working correct but wanted to know the tips to change the module enviornment name
 
@Apr Pillai
I use a piece of code like yours, founded somewhere on the web with an .accdb database (Access 2007).
All is fine IF the DB is in a trusted folder. As soon as I move the DB in other location (not "trusted") my work is go to hell because no code is allowed to run (including this one).

@syedadnan
Apr Pillai wrote:
Put a password and verify it in the second control.
Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
My advice is to keep a copy with no password. My own (very ugly) experience :)
 
You can prevent running a copy of your database on a different machine by checking the Machine name every time the database is open. If it is run on your own machine it will open normally, if the machine is different the user will not be able to open it.

Before you proceed with this I suggest you better take a backup of your database, and try it out on a new copy.

Even better you can try it out in a new database and find out how the whole thing works before you implement it on your Production database. By the way you don't need to maintain the table(s) with user/machine name.

  1. Find out your own machine name.
    Probably you know this already. I don't know which version of Windows you are using. In my machine (windows7) it is visible by expanding the Nerwork folder in Explorer window. Do the following to find the machine name:
    • Click on Start Menu.
    • Type cmd in the 'Search Program and files' control and press Enter.
    • Type Set in the DOS prompt window.
      You will find the Environment setting listed on the window.
    • Move the Scrollbar and find the entry COMPUTERNAME = USER-PC.
      USER-PC is my machine's name given as an example.
    • Note down your machine name and then type Exit to close the DOS command window.
  2. Open Access and create a new Database.
  3. Press ALT+F11 to open the VBA Window.
  4. Select Module from Insert menu and create a new Module.
  5. Copy and Paste the following Code into the Module:
    Code:
    Function SetBypassProperty()
    Const DB_Boolean As Long = 1
        ChangeProperty "AllowBypassKey", DB_Boolean, False
        CheckMachine
    End Function
    
    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
    
    Public Function CheckMachine()
    Dim strMachine As String
    strMachine = Environ("COMPUTERNAME")
    
    If strMachine = "USER-PC" Then
        'MsgBox "Authorized"
    Else
        MsgBox "Not Authorized"
        DoCmd.Quit
    End If
    
    End Function
  6. Replace USER-PC in the Code with your own machine name.
    NB: There are three programs in the above code. First two programs prevents the User from using the Shift-Key and open the database without running any code or Macro. Third Program checks the Machine Name where the database is going to run. If the machine name doesn't match with the name you have given in the above code then MS-Access itself will be closed.
  7. Select databasename Properties (like db3 Properties) from Tools Menu.
  8. Select Protection Tab.
  9. Put check mark in the Lock Project from Viewing
  10. Put a password and verify it in the second control.
    Remember this password (write it down in a safe place), you need this to open the VBA Modules for editing.
  11. Click OK to save and close the control.
  12. Open a new macro and select RunCode in the Action column.
  13. Type SetBypassProperty() in the Function Name argument.
  14. Save the Macro with the name Autoexec
  15. Save and Close the Database.
  16. Open the database and check whether the database is opening normally on your Machine.
  17. Make a copy of the database and take it to another machine and try opening it on that machine.




Could you please let me know if i want to add 1 to 3 user name means machine name is it possible ?
 
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")

If strMachine = "USER-PC" Then
'MsgBox "Authorized"
Else
MsgBox "Not Authorized"
DoCmd.Quit
End If

End Function

Replace the above code with the following Code:

Code:
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")

Select Case strMachine
       Case "USER-PC", "ABC-PC", "ZYX-PC"
           'Authorized
       Case Else
           MsgBox "Not Authorized"
           DoCmd.Quit
End Select

End Function

Replace the Computer names with your own.
 
Replace the above code with the following Code:

Code:
Public Function CheckMachine()
Dim strMachine As String
strMachine = Environ("COMPUTERNAME")

Select Case strMachine
       Case "USER-PC", "ABC-PC", "ZYX-PC"
           'Authorized
       Case Else
           MsgBox "Not Authorized"
           DoCmd.Quit
End Select

End Function

Replace the Computer names with your own.



Thanks Dear .. Thanks a Lot, McDonald Says I'm Love in it and i say I love your kindness....
 
@synedadnan - Please could you refrain from quoting the entire previous text in your replies - it make the threads unnecessarily long and difficult to read. Simply trim out all the quoted text except what is relevant to your response.
 

Users who are viewing this thread

Back
Top Bottom