我有一个以.vbs结尾的文本文件,我在下面写了:
Set Conn = CreateObject("ADODB.Connection")
Conn.Provider = "Microsoft.ACE.OLEDB.12.0"
Conn.Properties("Data Source") = "C:\dummy.accdb"
Conn.Properties("Jet OLEDB:Database Password") = "pass"
Conn.Open
Conn.Close
Set Conn = Nothing
无法找到提供商。它可能没有正确安装。
但它已安装。我认为问题的根源是提供者是32位提供者,据我所知它不存在为64位。
如果我在64位计算机上通过IIS运行VBScript(作为ASP文件),我可以选择它应该以32位模式运行。然后它可以找到提供者。
如何在Windows 64位上找到提供程序?我可以告诉CScript(执行.vbs文本文件)以某种方式在32位模式下运行吗?
答案 0 :(得分:66)
关注http://support.microsoft.com/kb/896456
要启动32位命令提示符,请按照下列步骤操作:
* Click Start, click Run, type %windir%\SysWoW64\cmd.exe, and then click OK.
然后输入
cscript vbscriptfile.vbs
答案 1 :(得分:17)
' C:\Windows\System32\WScript.exe = WScript.exe
Dim ScriptHost : ScriptHost = Mid(WScript.FullName, InStrRev(WScript.FullName, "\") + 1, Len(WScript.FullName))
Dim oWs : Set oWs = CreateObject("WScript.Shell")
Dim oProcEnv : Set oProcEnv = oWs.Environment("Process")
' Am I running 64-bit version of WScript.exe/Cscript.exe? So, call script again in x86 script host and then exit.
If InStr(LCase(WScript.FullName), LCase(oProcEnv("windir") & "\System32\")) And oProcEnv("PROCESSOR_ARCHITECTURE") = "AMD64" Then
' rebuild arguments
If Not WScript.Arguments.Count = 0 Then
Dim sArg, Arg
sArg = ""
For Each Arg In Wscript.Arguments
sArg = sArg & " " & """" & Arg & """"
Next
End If
Dim sCmd : sCmd = """" & oProcEnv("windir") & "\SysWOW64\" & ScriptHost & """" & " """ & WScript.ScriptFullName & """" & sArg
WScript.Echo "Call " & sCmd
oWs.Run sCmd
WScript.Quit
End If
答案 2 :(得分:14)
如果您可以控制运行cscript可执行文件,那么运行{32}实现的X:\windows\syswow64\cscript.exe
版本。
答案 3 :(得分:2)
' ***************
' *** 64bit check
' ***************
' check to see if we are on 64bit OS -> re-run this script with 32bit cscript
Function RestartWithCScript32(extraargs)
Dim strCMD, iCount
strCMD = r32wShell.ExpandEnvironmentStrings("%SYSTEMROOT%") & "\SysWOW64\cscript.exe"
If NOT r32fso.FileExists(strCMD) Then strCMD = "cscript.exe" ' This may not work if we can't find the SysWOW64 Version
strCMD = strCMD & Chr(32) & Wscript.ScriptFullName & Chr(32)
If Wscript.Arguments.Count > 0 Then
For iCount = 0 To WScript.Arguments.Count - 1
if Instr(Wscript.Arguments(iCount), " ") = 0 Then ' add unspaced args
strCMD = strCMD & " " & Wscript.Arguments(iCount) & " "
Else
If Instr("/-\", Left(Wscript.Arguments(iCount), 1)) > 0 Then ' quote spaced args
If InStr(WScript.Arguments(iCount),"=") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), "=") + 1) & """ "
ElseIf Instr(WScript.Arguments(iCount),":") > 0 Then
strCMD = strCMD & " " & Left(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") ) & """" & Mid(Wscript.Arguments(iCount), Instr(Wscript.Arguments(iCount), ":") + 1) & """ "
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
Else
strCMD = strCMD & " """ & Wscript.Arguments(iCount) & """ "
End If
End If
Next
End If
r32wShell.Run strCMD & " " & extraargs, 0, False
End Function
Dim r32wShell, r32env1, r32env2, r32iCount
Dim r32fso
SET r32fso = CreateObject("Scripting.FileSystemObject")
Set r32wShell = WScript.CreateObject("WScript.Shell")
r32env1 = r32wShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%")
If r32env1 <> "x86" Then ' not running in x86 mode
For r32iCount = 0 To WScript.Arguments.Count - 1
r32env2 = r32env2 & WScript.Arguments(r32iCount) & VbCrLf
Next
If InStr(r32env2,"restart32") = 0 Then RestartWithCScript32 "restart32" Else MsgBox "Cannot find 32bit version of cscript.exe or unknown OS type " & r32env1
Set r32wShell = Nothing
WScript.Quit
End If
Set r32wShell = Nothing
Set r32fso = Nothing
' *******************
' *** END 64bit check
' *******************
将上述代码放在脚本的开头,后续代码将以32位模式运行,并可访问32位ODBC驱动程序。 Source
答案 4 :(得分:2)
我们可以强制vbscript始终以32位模式运行,方法是将“system32”更改为“sysWOW64”,默认值为“Computer \ HKLM \ SOFTWARE”\ Classes \ VBSFile \ Shell \ Open \ Command“
答案 5 :(得分:1)
在64位计算机上运行32位脚本的备用方法: %windir%\ syswow64 \ cscript.exe vbscriptfile.vbs
答案 6 :(得分:1)
在启动器脚本中你可以强制它,它允许为两个架构保持相同的脚本和相同的启动器
:: For 32 bits architecture, this line is sufficent (32bits is the only cscript available)
set CSCRIPT="cscript.exe"
:: Detect windows 64bits and use the expected cscript (SysWOW64 contains 32bits executable)
if exist "C:\Windows\SysWOW64\cscript.exe" set CSCRIPT="C:\Windows\SysWOW64\cscript.exe"
%CSCRIPT% yourscript.vbs