How to make a file, Machine Dependent (1 Viewer)

ariansman

Registered User.
Local time
Yesterday, 18:00
Joined
Apr 3, 2012
Messages
157
How can we make an access or excel file to be dependent on the current computer. In other words the file will not work if it is copied and moved to another machine.
thank you
 

Solo712

Registered User.
Local time
Yesterday, 21:00
Joined
Oct 19, 2012
Messages
828
In the alternative, you can execute/deny the restricted file requests based on the machine Mac Address (which is unique for each computer). Call the function below and then match to the saved Mac Address string.

Code:
Private Function GetMac() As String
Dim objWMIService As Object, objItem As Object, colItems As Variant
    GetMac = ""
    Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")
 
    For Each objItem In colItems
        'MsgBox Nz(objItem.Name, "") & " / " & Nz(objItem.MACAddress, "")
        If InStr(objItem.Name, "etwork") <> 0 Then
           If Not IsNull(objItem.MACAddress) Then
             GetMac = objItem.MACAddress
             ' Label24.Caption = objItem.MACAddress
             Exit For
           End If
        End If
    Next
End Function

Best,
Jiri
 

ariansman

Registered User.
Local time
Yesterday, 18:00
Joined
Apr 3, 2012
Messages
157
thank you very much,
lets imagine my machine mac address is ff:ff:ff:ff:ff:ff. then where in your formula i should put it.
And where i should put the whole code? will the code run automatically when the file is being loaded?
thank you very much

In the alternative, you can execute/deny the restricted file requests based on the machine Mac Address (which is unique for each computer). Call the function below and then match to the saved Mac Address string.

Code:
Private Function GetMac() As String
Dim objWMIService As Object, objItem As Object, colItems As Variant
    GetMac = ""
    Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")
 
    For Each objItem In colItems
        'MsgBox Nz(objItem.Name, "") & " / " & Nz(objItem.MACAddress, "")
        If InStr(objItem.Name, "etwork") <> 0 Then
           If Not IsNull(objItem.MACAddress) Then
             GetMac = objItem.MACAddress
             ' Label24.Caption = objItem.MACAddress
             Exit For
           End If
        End If
    Next
End Function

Best,
Jiri
 

ariansman

Registered User.
Local time
Yesterday, 18:00
Joined
Apr 3, 2012
Messages
157
thank you very much,
lets imagine my machine mac address is ff:ff:ff:ff:ff:ff. then where in your formula i should put it.
And where i should put the whole code? will the code run automatically when the file is being loaded?
thank you very much

can anybody help me on this please?:(
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 21:00
Joined
Jan 23, 2006
Messages
15,386
What exactly is the issue?
The GetMac() works for me Win10 Home, Access 2010
 
Last edited:

ariansman

Registered User.
Local time
Yesterday, 18:00
Joined
Apr 3, 2012
Messages
157
thank you jdraw,
the issue is i want my access file to be opened only in a specific computer, so that if the file is stolen it does not open.
Solo712 provided a function. i am not an acces expert, so i dont know how to change that function if my computer mac is ff:ff:ff:ff:ff:ff. moreover where i should put the function so that it runs as the access file is opening and prevents it to be opened if it is on a stranger computer.
thank you
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 20:00
Joined
Feb 28, 2001
Messages
27,235
I cannot address the Excel part. Never played with Excel macros.

For Access, if an application has been secured and set up so that you turned off the bypass keys and only distributed an ACCDE or MDE (compiled) file and set it up to use a switchboard or dispatcher form, you can have the Form_Open event code of the switchboard perform this check. The trick will be to have a way to actually initially load the MAC address for the machine you wanted to be able to run the code.

You can find out about the above topics by doing a SEARCH on this forum (see the thin blue ribbon near the top of the page) on "switchboard" "opening form" "securing a database" "compiling a database"

You should, however, be aware that you cannot completely stop any of this. You can only make it harder to crack so that you deter MOST users. If someone steals the code and imports its parts to a new, blank database (rather than launching the original app file), that person can undo any of the "hardening" that you tried to do. It isn't pretty but it IS a fact of life.
 

jdraw

Super Moderator
Staff member
Local time
Yesterday, 21:00
Joined
Jan 23, 2006
Messages
15,386
As DocMan said, this is only a partial solution.
Also, as he said, you have to get the Value for the CustomProperty from the machine you intend to limit this database to. Then, you have to Create the Property on that machine. Then you create an autoexec macro that uses the name of the CustomProperty and then Compare the Value of the CustomProperty from the machine against the Value you assigned to that Custom Property.

I am not an Excel user either.

Here is the code I used to mockup the approach
Get the MacAddress and Create a CustomProperty ( I called it "CorrectMACAddress") . I did not create the autoexec macro, but I'm sure there are plenty of examples available through Google/Bing.

Code:
'---------------------------------------------------------------------------------------
' Procedure : jtProp
' Author    : mellon
' Date      : 11-Mar-2017
' Purpose   : Routine to test
'               -create a CustomProperty
'               -getting the MACAddress of current machine
'               -list all properties
'
'Note: You can only create a specifc CustomProperty once
'      So uncomment this line to delete the CustomProperty
'         'db.Properties.Delete "CorrectMacAddress"
'
' Dependency: Function GetMAC
'             Function CreateCustomProperty
'
'  available from https://access-programmers.co.uk/forums/showthread.php?t=243000
'---------------------------------------------------------------------------------------
'
Sub jtProp()
    Dim db As DAO.Database
    Dim P As DAO.Property
10    On Error GoTo jtProp_Error

20    Set db = DBEngine(0)(0)

    '***For testing I need ability to delete the custom Property
'    db.Properties.Delete "CorrectMacAddress"
'
    Dim strCustomPropertyName As String
    Dim strCustomPropertyValue As String
'
'    'identify the name of the CustomProperty
30    strCustomPropertyName = "CorrectMACAddress"
'
'    'get the value to be assigneed to the CustomProperty
40    strCustomPropertyValue = GetMac()
'
50    Call CreateCustomProperty(strCustomPropertyName, strCustomPropertyValue)

    'Iterate the custom properties to see what exists

60    For Each P In db.Properties
70      Debug.Print P.name & " :  " & P.value
80    Next P
90    On Error GoTo 0
100   Exit Sub

jtProp_Error:        'Trap some errors re Property
110   If err.number = 3270 Then
120     Debug.Print err.number & "  " & err.Description
130   ElseIf err.number = 3265 Then
140     Debug.Print err.number & "  " & err.Description
150   ElseIf err.number = 3251 Then
160     Debug.Print err.number & "  " & err.Description
170   Else
180     MsgBox "Error " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure jtProp of Module WinMgmtStuff"
190   End If
200   Resume Next
End Sub

Hope this helps.
 

Users who are viewing this thread

Top Bottom