2013-02-25 38 views
2

我正在嘗試使用VBS腳本更新MDB。在一臺機器上,它工作正常(WinXP和Office 2003),但另一臺機器上(Win7 64位VM,Office 2010)出現錯誤「ActiveX組件無法創建對象:'DAO.DBEngine.36'」。代碼:通過VBS訪問MDB

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

我試圖與DAO.DBEngineDAO.DBEngine.120.140沒什麼區別。
我不明白問題在哪裏。任何線索?


更新:我發現我可以使它通過callink這樣的腳本工作:

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

顯然到32位打電話的WScript您必須從SysWow64資料調用它,而WScript的system32中是64位版本。有點奇怪...

+2

您是否使用[32位解釋器](http://stackoverflow.com/a/2429502/1630171)運行腳本? – 2013-02-25 17:02:07

+0

在考慮如何執行某些操作之前,我建議檢查它是否真正解決了問題。 – 2013-02-26 09:38:10

+0

@AnsgarWiechers:+1非常感謝,我沒有看到您的第一條評論中的鏈接!您應該將您的評論置於答案中,以便結束該問題。 – 2013-02-26 14:17:16

回答

1

您可能需要使用腳本解釋器的32位版本上運行腳本:

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

this answer採取了類似的問題。

4

在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 
+1

這似乎使我失去了參數:我有一行檢查它'如果WScript.Arguments.Count = 0那麼...'現在的行爲像沒有參數 – 2013-02-26 09:19:10

+0

謝謝你的答覆! – 2013-02-26 14:18:20

+0

@iDevlop - 這是擁有獨立腳本的基本思想。當然你可以修改我的函數來使用參數並將它們追加到'oShell.Run'命令中。 – 2013-02-26 17:17:06