none
Trusted locations- Registry setting RRS feed

  • Question

  • I have an A2013 application which uses the A2013 runtime to run a program (FE = ASwitch.accde, BE ASwitch.accdb) which is in folder C:\ASwitch. This program opens another program which resides in Logical Drive X:\  (FE = vd5.accde,  BE = vd5_be.accdb).

    I would like the ASwitch program to be able to create the registry entries for X:\, from within ASwitch.

    I used

    Function RegKeyExists2(i_RegKey As String) As Boolean
    Dim myWS As Object
    On Error GoTo ErrorHandler
    'access Windows scripting
    Set myWS = CreateObject("WScript.Shell")
    'try to read the registry key
    myWS.RegRead i_RegKey
    'key was found
    RegKeyExists2 = True
    Exit Function
    ErrorHandler:
    'key was not found
    RegKeyExists2 = False
    End Function
    
    Private Sub Command11_Click()
    If RegKeyExists2("HKEY_CURRENT_USER\Software\Microsof t\Office\15.0\Access\Security\Trusted Locations\Location10\") = False Then
    MsgBox ("Code for adding registry key")
    Else
    MsgBox ("Key exists - do nothing")
    End If 

    to check if the entry exists. If it exists it works fine. If the entry does not exist, the program does not enter the Error Handling part and it gives me the error shown below.

    Does anyone know why the error handler software is not executed?

    Does Trusted Locations work with mapped drives and in this case would I insert in the registry "X:\" as the Trusted Location?

    BTW, I have posted earlier the same question with Access World Forums.

    Regards,

    John

    Thursday, September 3, 2015 10:31 AM

Answers

  • Hi Dirk,

    The problem was solved when

        HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\AllowNetworkLocations

    was set to 1 on the specific PC.

    Thanks again

    • Marked as answer by JohnPapa05 Monday, September 7, 2015 10:24 AM
    Monday, September 7, 2015 10:24 AM

All replies

  • Hi John. Try putting an error handler within the other sub as well just to see if you can trap the error there.
    Thursday, September 3, 2015 1:16 PM
  • Good Morning John,

    As a side note, it is recommended that you not use the mapped drive but rather the UNC path of the FE and the BE. Too many issue relate to mapped drives. If you are interested in more, here are some links to info about UNC paths.

    https://en.wikipedia.org/wiki/Path_(computing)

    http://searchsoa.techtarget.com/definition/Universal-Naming-Convention

    One of the main reasons for not using a mapped drive is that a mapped drive can be dropped or changed without the user even knowing it.


    Just takes a click to give thanks for a helpful post or answer.
    Please vote “Helpful” or Mark as “Answer” as appropriate.
    Chris Ward
    Microsoft Community Contributor 2012

    Thursday, September 3, 2015 1:38 PM
  • When I test your code on my system, in my test Access 2010 database, it works fine.  Is it possible you have the VB option "Break on All Errors" set?

    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, September 4, 2015 4:40 AM
  • Thank you Dirk, Chris and DB Guy for your excellent answers.

    The reason that it did not enter the Error Handle was that Error Trapping was set to "Break on Unhandled Errors". I set it to Break in Class Module and it is fine. Dirk's pointer helped immensely.

    Regarding the other issue

    Does Trusted Locations work with mapped drives and in this case would I insert in the registry "X:\" as the Trusted Location?

    As I mentioned

    I have an A2013 application which uses the A2013 runtime to run a program (FE = ASwitch.accde, BE ASwitch.accdb) which is in folder C:\ASwitch. This program opens another program which resides in Logical Drive X:\  (FE = vd5.accde,  BE = vd5_be.accdb).
    

    I tried using the UNC path based on Chris' advice. Mind you that both FE and BE are in the same folder. It keeps on telling that X:\vd5_be.accdb may not be safe etc etc.

    1) Is there a way to disable all Trusted related messages?

    2) Might there be a problem with added network security? I have a meeting on Monday with the Network person to see if we can solve the problem.

    John

    Friday, September 4, 2015 1:35 PM
  • Just thinking aloud,

    Do I need to specify ALL 3 keys for the location to be trusted, or only Path is enough?

    1) AllowNetworkLocations

    2) AllowSubfolders

    3) Path.



    • Edited by JohnPapa05 Friday, September 4, 2015 1:54 PM
    Friday, September 4, 2015 1:40 PM
  • The reason that it did not enter the Error Handle was that Error Trapping was set to "Break on Unhandled Errors". I set it to Break in Class Module and it is fine.

    I'm glad it's working, but I don't entirely understand this solution.  I would think that "Break on Unhandled Errors" is what you want, and it's certainly the setting I had in my successful test.  And is there in fact a class module involved?  You haven't mentioned one.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, September 4, 2015 3:37 PM
  • I do not have a Class module. I click on a  form button which runs

    If RegKeyExists2("HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\Location10\") = False Then
             MsgBox ("Code for adding registry key")
    Else
             MsgBox ("Key exists - do nothing")
    End If
    

    and the function is in the same form

    Function RegKeyExists2(i_RegKey As String) As Boolean
     Dim myWS As Object
    
       On Error GoTo ErrorHandler
       'access Windows scripting
       Set myWS = CreateObject("WScript.Shell")
       'try to read the registry key
       myWS.RegRead i_RegKey
       'key was found
       RegKeyExists2 = True
       Exit Function
    ErrorHandler:
    MsgBox Err.Number
       'key was not found
       RegKeyExists2 = False
       MsgBox "Error"
     End Function
    

    Friday, September 4, 2015 3:45 PM
  • Just thinking aloud,

    Do I need to specify ALL 3 keys for the location to be trusted, or only Path is enough?

    1) AllowNetworkLocations

    2) AllowSubfolders

    3) Path.

    In the Trust Center UI, order to trust a folder on a network share, you have to check the box for "Allow Trusted Locations on my network".  Therefore, I would expect that if you are setting trusted locations directly in the registry, you'd have to set

        HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\AllowNetworkLocations

    to 1, to accomplish the same end.  You would not need to set the AllowSubfolders key of the location you added, unless you had some need to trust things in subfolders of that location.


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Friday, September 4, 2015 3:48 PM
  • Thanks Dirk,

    On my pc I have the settings you mention and it works.

    I will check on Monday the settings on the customer's pc.

    Saturday, September 5, 2015 5:14 AM
  • Hi Dirk,

    The problem was solved when

        HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Access\Security\Trusted Locations\AllowNetworkLocations

    was set to 1 on the specific PC.

    Thanks again

    • Marked as answer by JohnPapa05 Monday, September 7, 2015 10:24 AM
    Monday, September 7, 2015 10:24 AM