Check for Trusted Location using .bat file
-
Wednesday, May 02, 2012 6:43 PM
Hello,
The company I work for is beginnig to upgrade from Windows XP and Office 2003 to Windows 7 and Office 2007. We have many Access applications that we need to add the location of the local database to the trusted locations in order for the vba code to run without receiving the security warning. Most of our Access are started using a .bat file. I've been able to use the If exist in the batch file to check for c:\Program Files\Microsoft Office\Office12\MSACCESS.exe to determine if the user has Access 2007 installed. If Access 2007 is installed, a variable is set to accde otherwise the variable is set to mde.
I would also like to check if path for the local database is in the Trusted Locations for Access if the user has Access 2007 installed. If the path is not in the Trusted Locations, we would like to add it to prevent the user from receiving the security warning and having to add the path to the Trusted locations manually.
If the path for the local database is already loaded to the Trusted Locations, the batch file can then go to the section that opens the database.
The path we need to check for in the Trusted Locations locations is %USERPROFILE%\<appFolder>\
If anyone can help with the syntax I need it would be greatly appreciated.
All Replies
-
Wednesday, May 02, 2012 10:18 PM
Try this.
@echo off setlocal :: AddTRUpath.cmd
:: ADD Access2007 tusted path :: By Gastone Canali :: http://www.accessribbon.de/en/?Trust_Center:Trusted_Locations :: path to be added & description set dbpath=%USERPROFILE%\<appFolder>\
set Description=new trusted path :: access 2007 key set TrustedKey=HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations :: count trusted locations for /f %%N in ('reg query "%TrustedKey%" ^| find "HKEY_CURRENT_USER" ^| findstr /R /n "^" ^| find /C ":"') do set /a count=%%N REM check the presence of the Trusted location
(reg query "%TrustedKey%" /S |findstr /i %dbpath%) || ( for /L %%i in (0,1,%count%) do ( reg query "%TrustedKey%\Location%%i" ||( reg add "%TrustedKey%\Location%%i" /v "Description" /t reg_sz /d "%Description%" /f reg add "%TrustedKey%\Location%%i" /v "Path" /t reg_sz /d "%dbpath%" /f exit /b ) ) )
:: ***open db:: ***end
Gastone Canali >http://www.armadillo.it
Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE!- Marked As Answer by yerbme1d Thursday, May 03, 2012 7:25 PM
-
Thursday, May 03, 2012 6:10 PMThank you very much! This got me very close to what I wanted. It works fine if the path path is one of the trusted locations on the user's machine. However, if the path is not in the trusted locations it is added twice. Also, the 'exit /b' prevents the remainder of the .bat from running when path is added to the trusted locations. Do you have any suggestions to correct this behavior?
-
Thursday, May 03, 2012 7:29 PM
I sovled the problem of the path being added to the trusted locations twice with the following change
for /f %%N in ('reg query "%TrustedKey%" ^| find "HKEY_CURRENT_USER" ^| findstr /R /n "^" ^| find /C ":"') do set /a count=%%N-1
-
Thursday, May 03, 2012 8:29 PM
@echo off setlocal :: Set access tusted path :: By Gastone Canali v.0.2 :: http://www.accessribbon.de/en/?Trust_Center:Trusted_Locations :: path to be added & description set dbpath=c:\programdokokok set Description=new trusted path :: access 2007 key set TrustedKey=HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations :: no output set null= 2^>nul 1^>nul :: count trusted locations for /f %%N in ('reg query "%TrustedKey%" ^| find "HKEY_CURRENT_USER" ^| findstr /R /n "^" ^| find /C ":"') do set /a count=%%N (reg query "%TrustedKey%" /S |findstr /i /c:"%dbpath%") %null% || ( for /L %%i in (0,1,%count%) do ( reg query "%TrustedKey%\Location%%i" %null% || ( reg add "%TrustedKey%\Location%%i" /v "Description" /t reg_sz /d "%Description%" /f %null% reg add "%TrustedKey%\Location%%i" /v "Path" /t reg_sz /d "%dbpath%" /f %null% echo %dbpath% added exit /b ) ) )this is the correct version
Gastone Canali >http://www.armadillo.it
Se alcuni post rispondono al tuo quesito (non necessariamente i miei), ricorda di contrassegnarli come risposta e non dimenticare di contrassegnare anche i post utili . GRAZIE! -
Friday, May 04, 2012 12:07 AM
Filter
Optional
String
Enables you to limit the returned data by filtering on attributes specific to Lync Server 2010. For example, you can limit returned data to analog device contact objects that have been assigned a specific voice policy, or contacts that have not been assigned a specific voice policy.
The Filter parameter uses the same Windows PowerShell filtering syntax that is used by the Where-Object cmdlet. For example, a filter that returns only fax machines would look like this, with AnalogFax representing the Active Directory attribute, -eq representing the comparison operator (equal to), and $True (a built-in Windows PowerShell variable) representing the filter value:
-Filter {AnalogFax -eq $True}
It uses PowerSHell syntax so -like or -match is Ok.
¯\_(ツ)_/¯
- Edited by jrvMicrosoft Community Contributor Friday, May 04, 2012 12:09 AM

