Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591

    Setting Trusted Locations with VBA

    I've solved all my security questions except one. My db has been published as an accde. My last detail is to hide this security warning.
    Click image for larger version. 

Name:	Security Concern.JPG 
Views:	51 
Size:	36.9 KB 
ID:	43496



    I know how to fix this manually in the Trust Center, but it has to be done for each user. I want to set the Trusted Locations using VBA so we don't have to touch this. I also don't want to mess with the registry if I don't have to.

    My searches didn't turn up anything specific to using VBA.

    I'm hoping this is an easy trick to turn.

    Let me know.

  2. #2
    ranman256's Avatar
    ranman256 is online now VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    it has to be done manually otherwise hackers can override this security block.

  3. #3
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Not true. It can be done in various ways.
    In each case the idea is to set the location as trusted in the registry before opening the ACCDE file.

    Possible approaches include:
    1. Supply a .reg file with the trusted location info and ensure the file is 'run' (merged with the registry) before first use
    2. As above but using a .vbs script file
    3. Distribute your ACCDE file using professional installer software and include the registry info as part of the installer process

    I have used method 1 which works fine as long as end users follow instructions to run it first ...and providing registry editing isn't prohibited in thsat workplace.
    Ditto method 2
    However, I normally use method 3 as that is guaranteed to work.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #4
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    That leaves editing the registry which has worked for other apps we have built. A programmer set up bat files that did the installation and edited the registry. He's not available to assist at the moment.

    Here's a sample we've used many times for a different application.

    Code:
    @ECHO OFF
    
    ECHO Please wait while PAIRS is being updated....
    ECHO This window will automatically close once complete.
    
    
    IF EXIST "C:\PAIRS_64bit\" RMDIR "C:\PAIRS_64bit" /S /Q
    
    
    xcopy "\\XYZ00000\PAIRS\Install\PAIRS_64Bit_Install\PAIRS_64bit" "C:\PAIRS_64bit\" /E /I
    
    
    xcopy "\\XYZ00000\PAIRS\Install\PAIRS_64Bit_Install\PAIRS_64bit\Links\PAIRS_64bit.lnk" "C:\Users\%USERNAME%\Desktop\" /Y
    
    
    "C:\PAIRS_64bit\Reg\PAIRS_64bit.reg"
    It seems to me all I'd have to do is run this one line to get what I want, but it has no affect. I still get the security warning.

    Code:
    "C:\FITS\reg\FITS.reg"

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    ALL methods of setting Trusted Locations require editing the registry!
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I've used this for years and never had a problem. No recall where I got it.
    I run it on startup in autoexec macro.

    Code:
    Public Function AddTrustedLocation()
        On Error GoTo err_proc
        'WARNING:  THIS CODE MODIFIES THE REGISTRY
        'sets registry key for 'trusted location'
    
    
        Dim intLocns As Integer
        Dim i As Integer
        Dim intNotUsed As Integer
        Dim strLnKey As String
        Dim reg As Object
        Dim strPath As String
        Dim strTitle As String
    
    
        strTitle = "Add Trusted Location"
        Set reg = CreateObject("wscript.shell")
        strPath = CurrentProject.Path
    
    
        'Specify the registry trusted locations path for the version of Access used
        strLnKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\" & Format(Application.Version, "##,##0.0") & _
                   "\Access\Security\Trusted Locations\Location"
    
    
        On Error GoTo err_proc0
        'find top of range of trusted locations references in registry
        For i = 999 To 0 Step -1
            reg.RegRead strLnKey & i & "\Path"
            GoTo chckRegPths        'Reg.RegRead successful, location exists > check for path in all locations 0 - i.
    checknext:
        Next
        MsgBox "Unexpected Error - No Registry Locations found", vbExclamation
        GoTo exit_proc
    
    
    
    
    chckRegPths:
        'Check if Currentdb path already a trusted location
        'reg.RegRead fails before intlocns = i then the registry location is unused and
        'will be used for new trusted location if path not already in registy
    
    
        On Error GoTo err_proc1:
        For intLocns = 1 To i
            reg.RegRead strLnKey & intLocns & "\Path"
            'If Path already in registry -> exit
            If InStr(1, reg.RegRead(strLnKey & intLocns & "\Path"), strPath) = 1 Then GoTo exit_proc
    NextLocn:
        Next
    
    
        If intLocns = 999 Then
            MsgBox "Location count exceeded - unable to write trusted location to registry", vbInformation, strTitle
            GoTo exit_proc
        End If
        'if no unused location found then set new location for path
        If intNotUsed = 0 Then intNotUsed = i + 1
    
    
        'Write Trusted Location regstry key to unused location in registry
        On Error GoTo err_proc:
        strLnKey = strLnKey & intNotUsed & "\"
        reg.RegWrite strLnKey & "AllowSubfolders", 1, "REG_DWORD"
        reg.RegWrite strLnKey & "Date", Now(), "REG_SZ"
        reg.RegWrite strLnKey & "Description", Application.CurrentProject.Name, "REG_SZ"
        reg.RegWrite strLnKey & "Path", strPath & "\", "REG_SZ"
    
    
    exit_proc:
        Set reg = Nothing
        Exit Function
    
    
    err_proc0:
        Resume checknext
    
    
    err_proc1:
        If intNotUsed = 0 Then intNotUsed = intLocns
        Resume NextLocn
    
    
    err_proc:
        MsgBox Err.description, , strTitle
        Resume exit_proc
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    How do you run that from an application that you're trying to install in a folder that isn't trusted? Wouldn't the macro run but the code not run (raising error 2001)?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Interesting discussion. Any thoughts on using a simple bat file to accomplish this, I swear it's worked for us in the past, but I can't seem to make it work for me nowe.

  9. #9
    moke123's Avatar
    moke123 is online now Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    Quote Originally Posted by Micron View Post
    How do you run that from an application that you're trying to install in a folder that isn't trusted? Wouldn't the macro run but the code not run (raising error 2001)?
    I'm not sure why but it seems to work. the location is added. I've not gotten the nag msg in years.

    I think I got it at UA some time ago. Of course trying to find it there now is impossible.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi Moke
    I haven't tried your code but am also surprised it would work as the security message precedes the startup form which itself precedes an autoexec macro.

    Paul
    I haven't written a .bat file in years so won't offer to edit what you showed earlier.
    In any case its adding unnecessary complication as a .reg file provides exactly what is needed to add a trusted location to the registry
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  11. #11
    Paul H's Avatar
    Paul H is offline Expert
    Windows 10 Access 2016
    Join Date
    Sep 2011
    Location
    Richmond, VA
    Posts
    591
    Quote Originally Posted by isladogs View Post
    In any case its adding unnecessary complication as a .reg file provides exactly what is needed to add a trusted location to the registry
    Is there a better hands free way to do this?

  12. #12
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    @moke123 - it must be version dependent then. I tried it and while the macro will execute, code will not.
    As mentioned, the "better" way is an installer run by someone who has the necessary install permissions. Outside of that, you'd need a way for anyone to be able to run a script that alters the registry, and in some places that's just not allowed.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  13. #13
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by Paul H View Post
    Is there a better hands free way to do this?
    See post #3
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  14. #14
    Shadow9449 is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    Feb 2017
    Posts
    38
    Quote Originally Posted by isladogs View Post
    Hi Moke
    I haven't tried your code but am also surprised it would work as the security message precedes the startup form which itself precedes an autoexec macro.
    Hi Colin

    I think that the thinking behind this type of code is that all you have to do is accept the nag screen ONCE and you'll never see it again. That's a whole lot easier than having to adjust the registry yourself and almost as good as using a .reg in the sense that it's one step less when deploying the application.

    Cheers

  15. #15
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Quote Originally Posted by Shadow9449 View Post
    Hi Colin

    I think that the thinking behind this type of code is that all you have to do is accept the nag screen ONCE and you'll never see it again. That's a whole lot easier than having to adjust the registry yourself and almost as good as using a .reg in the sense that it's one step less when deploying the application.

    Cheers
    You may be right but personally I'd rather use a .reg file. Its quick & easy
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Trusted locations
    By kcmiuser in forum Security
    Replies: 1
    Last Post: 08-14-2013, 09:48 AM
  2. Trusted Locations and Active X controls
    By justphilip2003 in forum Security
    Replies: 14
    Last Post: 05-17-2013, 08:02 AM
  3. Trusted Publisher
    By rovman in forum Access
    Replies: 1
    Last Post: 10-22-2011, 02:55 PM
  4. Replies: 0
    Last Post: 01-26-2011, 05:51 PM
  5. Replies: 0
    Last Post: 07-09-2010, 06:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums