如果“工具"菜单中没有“数字签名"项,我如何向 VBA Access 项目添加证书? [英] How can I add a certificate to VBA Access project if the Digital Signature item doesn't appear in the Tools menu?
问题描述
我正在尝试让 Access 2000 数据库在 Access 2010 运行时中运行,并删除有关文件不受信任的警告对话框.我做了一些研究并发现了 SelfCert.exe 程序.
我针对这种情况下的特定要求对其进行了修改.在 Access 2010 运行时中运行 Access 2000 数据库.您需要根据注册表设置为其他版本的运行时修改它.此外,我读到这在 Windows 8 中不起作用.但我也发现您不需要管理权限来运行此代码,因为它只修改注册表中的 HKEY_CURRENT_USER 配置单元,当前用户具有完全访问权限.>
公共函数 AddTrustedLocation()出错时转到 err_proc'警告:此代码修改注册表'您不需要管理员权限'因为它只影响 HK_CURRENT_USER 配置单元'为'可信位置'设置注册表项Dim intLocns 为整数Dim i 作为整数Dim intNotUsed 作为整数Dim strLnKey 作为字符串Dim reg 作为对象Dim strPath 作为字符串Dim strTitle 作为字符串strTitle = "添加可信位置"设置 reg = CreateObject("wscript.shell")strPath = CurrentProject.path'为 Access 2010 运行时指定注册表受信任位置路径strLnKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Access\Security\Trusted Locations\Location"出错时转到 err_proc0'在注册表中查找受信任位置引用范围的顶部对于 i = 999 到 0 步 -1reg.RegRead strLnKey &我&\小路"GoTo chckRegPths 'Reg.RegRead 成功,位置存在 >检查所有位置 0 - i 的路径.检查下一个:下一个MsgBox "意外错误 - 未找到注册表位置", vbExclamation转到 exit_procchckRegPths:'检查 Currentdb 路径是否已经是受信任的位置'reg.RegRead 在 intlocns = i 之前失败,则注册表位置未使用,并且'如果路径尚未在注册表中,则将用于新的受信任位置出错时转到 err_proc1:对于 intLocns = 1 到 ireg.RegRead strLnKey &intLocns &\小路"'如果路径已经在注册表中 ->出口如果 InStr(1, reg.RegRead(strLnKey & intLocns & "\Path"), strPath) = 1 然后转到 exit_proc下一个位置:下一个如果 intLocns = 999 那么MsgBox "超出位置计数 - 无法将可信位置写入注册表", vbInformation, strTitle转到 exit_proc万一'如果没有找到未使用的位置,则为路径设置新位置如果 intNotUsed = 0 那么 intNotUsed = i + 1'将可信位置注册表项写入注册表中未使用的位置出错时转到 err_proc:strLnKey = strLnKey &intNotUsed &\"reg.RegWrite strLnKey &"AllowSubfolders", 1, "REG_DWORD"reg.RegWrite strLnKey &日期",现在(),REG_SZ"reg.RegWrite strLnKey &描述",Application.CurrentProject.Name,REG_SZ"reg.RegWrite strLnKey &路径",strPath &"\", "REG_SZ"退出过程:设置 reg = 无退出函数err_proc0:继续检查下一步错误过程1:如果 intNotUsed = 0 那么 intNotUsed = intLocns简历 NextLocn错误过程:MsgBox Err.Description, , strTitle恢复 exit_proc结束函数
我将此功能添加到 AutoExec 宏中.当用户第一次登录时,他们确实会收到安全通知;但是,只要文档保留在它第一次运行的受信任位置,它就永远不会再次出现.呜呼!
I am trying to get an Access 2000 database to run in the Access 2010 runtime and remove the warning dialog about the file not being trusted. I have done some research and discovered the SelfCert.exe program. This is a good tutorial on certificates. And this, too. Even Microsoft had instructions for Access 2000 indicating that this menu item should exist. However, my Tools menu in the Access 2000 VBA IDE does not have the Digital Signature menu item. What's worse is that when I right-click on menu bar to customize the Tools menu, I do see the Digital Signature...
item in the customize list. When I click and drag to add it to the Tools menu, it disregards my command. How stubborn! If I click and drag anything else to the Tools menu, it works like a charm. What?!
How do I install that menu item? Or, better yet, how do I get my database not to have the security warning when I open it from Access 2010 runtime?
After some more significant research, I discovered the answer to my second question, which was ultimately what I wanted an answer to. How do I get rid of the potential security concern dialog when opening an Access 2000 database in the Access 2010 runtime?
Basically, you need to add the database to the list of trusted locations. The Access 2010 runtime does not offer a UI for this feature, so you have to do it programmatically. This website offers the code: Utter Access Add Trusted Location
I modified it for the specific requirements in this situation. Run an Access 2000 database in Access 2010 runtime. You will need to modify it for other versions of the runtime depending on the registry settings. Also, I read that this will not work in Windows 8. But I also found that you do NOT need administrative privileges to run this code because it only modifies the HKEY_CURRENT_USER hive in the registry, which the current user has full access to.
Public Function AddTrustedLocation()
On Error GoTo err_proc
'WARNING: THIS CODE MODIFIES THE REGISTRY
'You do not need administrator privileges
'since it only affects the HK_CURRENT_USER hive
'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 Access 2010 runtime
strLnKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\14.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
I added this function to the AutoExec macro. When the user first logs on, they do receive the security notice; however, it will never appear again as long as the document remains in the trusted location it was first run at. Woo-hoo!
这篇关于如果“工具"菜单中没有“数字签名"项,我如何向 VBA Access 项目添加证书?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!