I have a function tied to my main forms on open event that adds the current db path as a trusted location to avoid the macro warnings each time the db is opened: - Function MakeTrustedLocation()
-
On Error GoTo ET
-
-
Dim strFile As String, strLocation As String, strKey As String, strSql As String, strMsg As String
-
-
strKey = "[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\MyTrustedPath]"
-
-
strLocation = Application.CurrentProject.Path & "\"
-
strLocation = Replace(strLocation, "\", "\\")
-
strFile = "C:\TEMP\TrustMyApplication.reg"
-
Open strFile For Output As #1
-
Print #1, "Windows Registry Editor Version 5.00"
-
Print #1, ""
-
Print #1, strKey
-
Print #1, """Path""=""" & strLocation & """"
-
Print #1, """AllowSubfolders""=dword:00000001"
-
Close #1
-
Shell ("regedit /s " & strFile)
-
Kill (strFile)
-
Exit Function
-
ET:
-
strMsg = Err.Number & " - " & Err.Description
-
Debug.Print strMsg
-
-
End Function
-
No need to execute this code each time the main form opens. So I would like to check if the registry entry exists and is equal to the current db path. If so, then exit function.
Thanks for the look,
Tux
9 10229
Hey Tux;
There is a class module that you can download and add to your project, called cRegistry. This module will allow you to do just about whatever you want with the registry.
Instructions for it's use and a link to download are here.
Thanks Don. How does this class module integrate into Access VBA? In the meantime, here is my solution: - '--- reads the value for the registry key strChkKey. if the key cannot be found, the return value is ""
-
-
Function RegKeyRead()
-
'On Error GoTo ET
-
-
Dim myWS As Object
-
Dim RegKeyMe As String
-
Dim strAppPath As String
-
Dim strChkKey As String
-
-
'--- store the path of the current registry key in variable if key is present
-
strChkKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\HyattInjuryDb\Path"
-
-
'--- try to read the reg key
-
On Error GoTo NewKey
-
'--- use Windows scripting to read the registry key
-
Set myWS = CreateObject("WScript.Shell")
-
myWS.RegRead (strChkKey) ' if key does not exist, an error will result. in this case, create a new key
-
-
'--- store the full path to our current project
-
strAppPath = CurrentProject.Path & "\"
-
-
'--- read key from registry and store in variable RegKeyMe
-
RegKeyMe = myWS.RegRead(strChkKey)
-
-
'--- MsgBox RegKeyMe, , "RegKeyMe"
-
'--- MsgBox strAppPath, , "strAppPath"
-
-
If RegKeyMe <> strAppPath Then
-
-
NewKey:
-
-
'--- MsgBox "need to add new reg key"
-
-
Dim strFile As String, strLocation As String, strKey As String, strSql As String, strMsg As String
-
-
strKey = "[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Access\Security\Trusted Locations\HyattInjuryDb]"
-
-
strLocation = Application.CurrentProject.Path & "\"
-
strLocation = Replace(strLocation, "\", "\\")
-
strFile = "C:\TEMP\TrustMyApplication.reg"
-
Open strFile For Output As #1
-
Print #1, "Windows Registry Editor Version 5.00"
-
Print #1, ""
-
Print #1, strKey
-
Print #1, """Path""=""" & strLocation & """"
-
Print #1, """AllowSubfolders""=dword:00000001"
-
Close #1
-
Shell ("regedit /s " & strFile)
-
Kill (strFile)
-
Exit Function
-
-
Else
-
-
'--- MsgBox "key is good to go"
-
-
End If
-
-
ET:
-
strMsg = Err.Number & " - " & Err.Description
-
Debug.Print strMsg
-
Exit Function
-
-
End Function
-
Thanks
Hey Tux,
On the page link that I posted you can copy the text from the module. In your access project create a new class module with the name cRegistry and paste the copied code into it.
The page has all the examples that you need on using the module.
ADezii 8,834
Recognized Expert Expert
Just subscribing, will return later.
ADezii 8,834
Recognized Expert Expert
Oh well, here I am again. You can use this code to specifically check and see if a Registry Key exists: - First, the API Declaration:
- Public Declare Function RegOpenKeyEx _
-
Lib "advapi32.dll" Alias "RegOpenKeyExA" _
-
(ByVal hKey As Long, ByVal lpSubKey As String, _
-
ByVal ulOptions As Long, ByVal samDesired As Long, _
-
phkResult As Long) As Long
- In your specific case:
- Dim hKey As Long
-
Const conKEY_NAME = "Software\Microsoft\Ofvvfice\12.0\Access\Security\Trusted Locations\MyTrustedPath"
-
Const conHKEY_CURRENT_USER = &H80000001
-
Const READ_CONTROL = &H20000
-
Const STANDARD_RIGHTS_READ = (READ_CONTROL)
-
Const KEY_QUERY_VALUE = &H1
-
Const KEY_ENUMERATE_SUB_KEYS = &H8
-
Const KEY_NOTIFY = &H10
-
Const SYNCHRONIZE = &H100000
-
-
Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or _
-
KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And _
-
(Not SYNCHRONIZE))
-
-
'Attempt to Open the requested Key
-
If RegOpenKeyEx(conHKEY_CURRENT_USER, conKEY_NAME, 0, KEY_READ, hKey) <> 0 Then
-
MsgBox "The Registry Key [" & conKEY_NAME & "] does not exist!"
-
Else
-
MsgBox "The Registry Key [" & conKEY_NAME & "] does exist!"
-
End If
Thanks again Adezii. I had a thought on this:
I'm only interested in knowing if the project is opening from a trusted location. If the current project path has not been added as a trusted location, the key -
Software\Microsoft\Office\12.0\Access\Security\Tru sted Locations\MyTrustedPath\
would not exist (...\MyTrustedPath is added by my function). However, if the end user has previously set the db path as trusted, then move the db, the directory 'MyTrustedPath' will exist but the Path key will not match the current project path.
So would I need to approach this differently, and perform (2) checks, one to check for the existence of -
Software\Microsoft\Office\12.0\Access\Security\Tru sted Locations\MyTrustedPath\
and next, to check if the reg path key
Software\Microsoft\Office\12.0\Access\Security\Tru sted Locations\MyTrustedPath\ Path
matches the current project path?
Thanks again,
Tux
ADezii 8,834
Recognized Expert Expert @tuxalot
It would appear to me to be a 2-Step process, at least you should be able to isolate the problem should something go wrong.
Hi ADezii,
I'm getting an "invalid outside procedure" when compiling using this code. The error is at - If RegOpenKeyEx(conHKEY_CURRENT_USER, conKEY_NAME, 0, KEY_READ, hKey) <> 0 Then
-
Ideas?
ADezii 8,834
Recognized Expert Expert @tuxalot
The code is sound, I need to see the entire code context (the Procedure in which the Registry Key is Opened), as well as the API Declaration and where it is Declared RegOpenKeyEX().
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: build |
last post by:
G'day All,
I'm using code below to check a path selected by a user.
Can anyone pick holes in it please?
The more critical you are the better.
tia
build
'GET SOURCE PATH...
|
by: Bob |
last post by:
I'm working on a Windows app that needs to write to the Registry HKLM. I
keep getting a "System.UnauthorizedAccessException: Cannot write to the
registry key." error when running the app. I'm...
|
by: Dan Sikorsky |
last post by:
Should application data be read and written to the Registry to persist
state, or should the App.config file be used?
If the Registry should be used, what .NET class reads and writes the...
|
by: Yogi_Bear_79 |
last post by:
Been trying to do an IF statement to check for a registry key. I understand
to RegistryKey class in the Microsoft.Win32 namespace. But just can't get
the syntax correct. What I want is to test for...
|
by: zoneal |
last post by:
my program it's just tools for my little home network.. Only thing I
have left to do is reading the registy key
to check the path to the shared folder.. this path is always updated so
I will...
| |
by: eSolTec, Inc. 501(c)(3) |
last post by:
Thank you in advance for any and all assistance. It is greatly appreciated.
Is there a way to programmatically check for .NET Framework versions
installed on the computer?
--
Michael Bragg,...
|
by: MIRRA |
last post by:
Hi
I have a UNIX script which creates a report. In that script I have to define the java classpath. Also I need to check if the java classpath specified exists or not. Below is the command i use
...
|
by: jimpy |
last post by:
Greetings,
When I open a terminal and enter :"echo $PATH", I receive this printout:
I successfully add :
But when I close the terminal, and later reopen and check the path, the...
|
by: Floris Bruynooghe |
last post by:
Hi
We basically want the same as the OP in , i.e. when python starts
up we don't want to load *any* sys.path entries from the registry,
including subkeys of the PythonPath key. The result of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |