MS Access VBA 错误:运行时错误“70"权限被拒绝 [英] MS Access VBA Error: Run time error '70' Permission Denied

查看:39
本文介绍了MS Access VBA 错误:运行时错误“70"权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为此问题是最近更新到 MS Office/Access 或 Windows 10 的结果.当我运行此代码时:

Dim s As String使用 CreateObject("Scriptlet.TypeLib")s = Left(.Guid, 9)newguidx = Right(s, 8)结束于

我收到错误消息:With 语句中的权限被拒绝.这是新的,只有在我的管理员更新我们的系统后才会出现.我没有回滚更新的选项.有没有人遇到过这个问题并有解决办法?

操作系统:Windows 7 企业版访问版本:2010

谢谢

解决方案

来自微软:

<块引用>

这个问题是设计的,截至 7 月安全更新.此控件被阻止作为一项安全措施,以帮助防止恶意代码在 Office 应用程序中运行.我们正在努力使用推荐的方法发布知识库文章.在 KB 准备好之前,我会在此处发布内容:

解决方法首选方法是更改​​代码以使用 Windows API CoCreateGuid (https://msdn.microsoft.com/en-us/library/windows/desktop/ms688568(v=vs.85).aspx) 而不是 CreateObject("Scriptlet.TypeLib").Guid

' 没有可用的 VT_GUID,因此必须声明类型 GUID私有类型 GUID_TYPE数据1只要Data2 作为整数Data3 作为整数Data4(7) 作为字节结束类型私有声明 PtrSafe 函数 CoCreateGuid Lib "ole32.dll" (Guid As GUID_TYPE) As LongPtrPrivate Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (Guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr函数 CreateGuidString()Dim guid 为 GUID_TYPEDim strGuid 作为字符串Dim retValue As LongPtrconst guidLength As Long = 39 '带有空终止符的注册表 GUID 格式 {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}retValue = CoCreateGuid(guid)如果 retValue = 0 那么strGuid = String$(guidLength, vbNullChar)retValue = StringFromGUID2(guid, StrPtr(strGuid), guidLength)如果 retValue = guidLength 那么' 作为字符串的有效 GUIDCreateGuidString = strGuid万一万一结束函数

<块引用>

替代解决方法

这将允许您使用 CreateObject("Scriptlet.TypeLib")但它会减少 Office 2017 年 7 月安全更新添加的安全保护.您可以设置允许 Scriptlet.TypeLib 在 Office 应用程序内部实例化的注册表项.设置此注册表项后,Office 将不会阻止使用此 COM 控件.

  • 打开注册表编辑器.
  • 转到:计算机HKEY_LOCAL_MACHINESOFTWAREMicrosoftOffice16.0CommonCOM 兼容性{06290BD5-48AA-11D2-8432-006008C3FBFC}
    • 注意:您可能需要根据安装的 Office 版本搜索注册表以在 HKEY_LOCAL_MACHINE 下找到正确的位置.
  • 添加 ActivationFilterOverride
  • 设置双字:1

详细说明:

  1. 单击开始,单击运行,在打开框中键入 regedit,然后单击确定.在注册表中找到并单击以下项:HKEY_LOCAL_MACHINE
  2. 在编辑菜单上,指向查找,然后在查找内容:文本框中输入以下内容:COM 兼容性
  3. 确保键被选中,值和数据被取消选中.接下来选择仅匹配整个字符串,单击查找下一个找到并单击以下键:{06290BD5-48AA-11D2-8432-006008C3FBFC} 注意:如果密钥不存在,您需要添加它.在编辑菜单上,指向新建,然后单击项.输入 {06290BD5-48AA-11D2-8432-006008C3FBFC}
  4. 在编辑"菜单上,指向新建",然后单击DWORD(32 位)值"
  5. 为 DWORD 的名称键入 ActivationFilterOverride,然后按 Enter.
  6. 右键单击 ActivationFilterOverride,然后单击修改.
  7. 在数值数据框中,键入 1 以启用注册表项,然后单击确定.
  8. 请注意要禁用 ActivationFilterOverride 设置,请键入 0(零),然后单击确定".
  9. 退出注册表编辑器,然后重新启动任何打开的 Office 应用程序.

I believe this issue is a result of a recent update to MS Office/Access or Windows 10. When I run this code:

Dim s As String
With CreateObject("Scriptlet.TypeLib")
    s = Left(.Guid, 9)
   newguidx = Right(s, 8)
End With

I get an error: Permission Denied on the With Statement. This is new only only cropped up after my admins updated our systems. I have no option to roll back updates. Anyone come across this and have a work around?

OS: Windows 7 Enterprise Access Version: 2010

Thanks

解决方案

From Microsoft:

This issue is by design, as of the July security updates. This control is blocked as a security measure to help prevent malicious code from running in Office applications. We are working on getting a knowledgebase article out with the recommended method. Until that KB is ready, I'll post the content here:

Workaround The preferred method is to change the code to use Windows API CoCreateGuid (https://msdn.microsoft.com/en-us/library/windows/desktop/ms688568(v=vs.85).aspx) instead of CreateObject("Scriptlet.TypeLib").Guid

' No VT_GUID available so must declare type GUID
Private Type GUID_TYPE
    Data1 As Long
    Data2 As Integer
    Data3 As Integer
    Data4(7) As Byte
End Type
Private Declare PtrSafe Function CoCreateGuid Lib "ole32.dll" (Guid As GUID_TYPE) As LongPtr
Private Declare PtrSafe Function StringFromGUID2 Lib "ole32.dll" (Guid As GUID_TYPE, ByVal lpStrGuid As LongPtr, ByVal cbMax As Long) As LongPtr
Function CreateGuidString()
    Dim guid As GUID_TYPE
    Dim strGuid As String
    Dim retValue As LongPtr
    Const guidLength As Long = 39 'registry GUID format with null terminator {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

    retValue = CoCreateGuid(guid)
    If retValue = 0 Then
        strGuid = String$(guidLength, vbNullChar)
        retValue = StringFromGUID2(guid, StrPtr(strGuid), guidLength)
        If retValue = guidLength Then
            ' valid GUID as a string
            CreateGuidString = strGuid
        End If
    End if
End Function

Alternate Workaround

This will allow you to use CreateObject("Scriptlet.TypeLib")however it will lessen the security protection added by the Office July 2017 security update. You can set a registry key that will allow Scriptlet.TypeLib to instantiate inside of Office applications. When this registry key is set, Office will not block any use of this COM control.

  • Open Registry Editor.
  • Go to: ComputerHKEY_LOCAL_MACHINESOFTWAREMicrosoftOffice16.0CommonCOM Compatibility{06290BD5-48AA-11D2-8432-006008C3FBFC}
    • Note: you may need to search the registry to find the correct location under HKEY_LOCAL_MACHINE based on your installed Office version.
  • Add ActivationFilterOverride
  • Set DWORD: 1

Detailed Instructions:

  1. Click Start, click Run, type regedit in the Open box, and then click OK. Locate and then click the following key in the registry: HKEY_LOCAL_MACHINE
  2. On the Edit menu, point to Find, and then enter the following in the Find What: text box: COM Compatibility
  3. Ensure Keys is selected, and Values and Data are deselected. Next select Match whole string only, click Find Next Locate and then click the following key: {06290BD5-48AA-11D2-8432-006008C3FBFC} Note: if the key is not present you will need to add it. On the Edit menu, point to New, and then click Key. Type in {06290BD5-48AA-11D2-8432-006008C3FBFC}
  4. On the Edit menu, point to New, and then click DWORD (32-bit) Value
  5. Type ActivationFilterOverride for the name of the DWORD, and then press Enter.
  6. Right-click ActivationFilterOverride, and then click Modify.
  7. In the Value data box, type 1 to enable the registry entry, and then click OK.
  8. Note to disable the ActivationFilterOverride setting, type 0 (zero), and then click OK.
  9. Exit Registry Editor, and then restart any open Office application.

这篇关于MS Access VBA 错误:运行时错误“70"权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆