gpt4 book ai didi

vbscript - 通过 VBS 访问 MDB

转载 作者:行者123 更新时间:2023-12-02 22:12:13 27 4
gpt4 key购买 nike

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

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

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


更新:我发现我可以通过调用这样的脚本来让它工作:

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

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

最佳答案

在 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

关于vbscript - 通过 VBS 访问 MDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15069440/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com