【问题标题】:Accessing MDB through VBS通过 VBS 访问 MDB
【发布时间】:2013-02-10 17:49:12
【问题描述】:

我正在尝试使用 VBS 脚本更新 MDB。在一台机器上它工作正常(WinXP 和 Office 2003),但在另一台机器上(Win7 64 位 VM 和 Office 2010)我收到错误“ActiveX 组件无法创建对象:'DAO.DBEngine.36'强>”。代码:

Dim dbe
Set dbe = CreateObject("DAO.DBEngine.36")

我试过DAO.DBEngineDAO.DBEngine.120.140 没有区别。
我不明白问题出在哪里。有什么线索吗?


更新:我发现我可以通过像这样调用脚本来使其工作:

c:\windows\syswow64\wscript MyScript.vbs Myargument

显然要调用 32 位 Wscript 必须从 syswow64 调用它,而 system32 中的 Wscript 是 64 位版本。有点奇怪……

【问题讨论】:

  • 您是否使用32-bit interpreter 运行脚本?
  • 在考虑如何强制执行某些事情之前,我建议先检查一下它是否真的解决了问题。
  • @AnsgarWiechers:+1 非常感谢,我没有在您的第一条评论中看到链接!您应该将您的评论放在答案中,以便我关闭问题。

标签: vbscript dao jet


【解决方案1】:

您可能需要使用 32 位版本的脚本解释器运行脚本:

%SystemRoot%\SysWOW64\wscript.exe C:\path\to\script.vbs

取自this answer 到一个类似的问题。

【讨论】:

    【解决方案2】:

    在 64 位操作系统中,.vbs 以 64 位进程启动,因此您需要(在开始时)将脚本重新启动为 32 位进程。

    'call it here
    Force32bit
    
    Dim dbe
    Set dbe = CreateObject("DAO.DBEngine.36")
    
    'just for testing:
    WScript.Echo TypeName(dbe) 'DBEngine
    
    'the rest of the code here...
    Set dbe = Nothing
    
    Sub Force32bit()
        Dim sWinDir, sSys64, sSys32, oShell
        Set oShell = CreateObject("WScript.Shell")
        sWinDir = oShell.ExpandEnvironmentStrings("%WinDir%")
        With CreateObject("Scripting.FileSystemObject")
            sSys64 = .BuildPath(sWinDir, "SysWOW64")
            If Not .FolderExists(sSys64) Then Exit Sub
            sSys32 = .BuildPath(sWinDir, "System32")
            If sSys32 = WScript.Path Then
                oShell.CurrentDirectory = sSys64
                oShell.Run "wscript.exe " & Chr(34) & _
                WScript.ScriptFullName & Chr(34), 1, False
                WScript.Quit
            End If
        End With
    End Sub
    

    【讨论】:

    • 这似乎让我失去了论据:我有一行用 if WScript.Arguments.Count = 0 then ... 检查它现在的行为就像没有提供任何参数
    • @iDevlop - 这是拥有独立脚本的基本理念。当然,您可以修改我的函数以使用参数并将它们附加到oShell.Run 命令。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多