Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set Trusted Location via VBA?

Status
Not open for further replies.

sudakov

Programmer
Jun 17, 2007
53
US
Hello.
Does anybody know how to set Trusted Location in Trust Center via VBA?

Thank you.
sudakov.
 
I do it via a reg key
Code:
[HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\Location1]
"Date"="28.04.2011 09:37"
"Description"="My Application"
"Path"="C:\\Path_To_My_Application\\"
"AllowSubfolders"=dword:00000001



"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
Hi DMF,

can you elaborate on your suggestion? Is this a solution for multiple users and if so, how would I implement it?

Thanks, georgesOne
 
Well the way I do it is to package all my Access application up using the solution packager and a complied ACCDE version of the application (which gets converted to an ACCDR - runtime version).

We run all our Access applications using the Access 2010 Runtime, eliminating the need to have Office with Access included (pro version), if you ensure you use late bindings for all Office integration in your Access application, it will then work for any installed version of Office the client machine might have installed.

There is a section in the solution packager to include a regkey so when the user installs your application from the packaged setup installer, the regkey is also added to the client machine's registry.

Alternatively simply create a regkey file and have your users run it (double click it) to have it added to the client registry.

I'd not recommend you have the end user try to manually add the regkey!

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Dance Music Downloads
 
I use a script similar to following which creates a local folder, sets it to trusted, copies the current application file, and opens the file.

Code:
'===================
' File: TrustCopyRun.vbs
'===================
   Const SystemFolder= 1
   Dim fso  'to be used for file related code
   Dim SysFolder
   Dim SysFolderPath
   dim strUserLogin 
   Dim RegEdPath
   Dim strAppFolder
   Dim strAppName
   Dim strAppFile
   Dim strAppNetworkFile 
'==============================================================
'  edit the values in the next three lines to match your application and network location
   strAppName = "MyAppName"
   strAppFile = "MyAppName.accdb"
   strAppNetworkFile = "N:\Applications\MyAppName.accdb"
'==============================================================
   Set fso = wscript.CreateObject("Scripting.FileSystemObject")
   Set SysFolder =fso.GetSpecialFolder(SystemFolder)
   SysFolderPath= SysFolder.Path

   'initialize the script shell object
   Set WshShell = WScript.CreateObject("WScript.Shell")
   strUserLogin = WshShell.ExpandEnvironmentStrings("%USERNAME%") 
   strAppFolder = "C:\users\" & strUserLogin & "\" & strAppName
   if not fso.FolderExists(strAppFolder) Then
      fso.CreateFolder strAppFolder
   End If

   'Office 12
   RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\"
   WshShell.RegWrite  RegEdPath  ,strAppName
   'Write the values into the registry
   WshShell.RegWrite  RegEdPath & strAppName & "\Path" , "C:\Users\" & strUserLogin & "\" & strAppName & "\"
   WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

   'Office 14
   RegEdPath = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\"
   WshShell.RegWrite  RegEdPath  ,strAppName
   'Write the values into the registry
   WshShell.RegWrite  RegEdPath & strAppName & "\Path" , "C:\Users\" & strUserLogin & "\" & strAppName & "\"
   WshShell.RegWrite  RegEdPath & strAppName & "\AllowSubfolders" , 1, "REG_DWORD"

   'copy the application file from the network location to the local folder 
   fso.CopyFile strAppNetworkFile ,strAppFolder & "\", 1
   'run the application
   wshshell.Run strAppFolder & "\" & strAppFile

wscript.Quit

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top