Eine VBS-Datei startet unter Win64 mit der 64-Bit-Version des Scripting Hosts. Meistens fällt dies nicht weiter auf. Scripte, in denen 32-Bit-Datenbanktreiber verwendet werden, funktionieren aber nicht mehr. Mit folgendem Scriptcode kann man dynamisch eine Ausführung im 32-Bit-Subsystem erzwingen:
'ensure script execution in Win32 subsystem on Win64 OS
f1 = (InStr(1, WScript.FullName, "system32", 1) > 0)
f2 = CreateObject("Scripting.FileSystemObject").FolderExists("C:\Windows\SysWOW64")
If f1 And f2 Then
Dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.CurrentDirectory = "C:\Windows\SysWOW64"
'keep possible command line arguments
For Each arg In WScript.Arguments
If InStr( arg, " " ) Then arg = """" & arg & """"
s = s & " " & arg
Next
wsh.Run "wscript.exe """ & WScript.ScriptFullName & """" & s, 1, False
WScript.Quit
End If
'test: show that actually the 32 bit version of wscript is now running
MsgBox WScript.FullName
'script code referencing 32 bit DLLs goes here
'(...)
'ensure script execution in Win32 subsystem on Win64 OS
f1 = (InStr(1, WScript.FullName, "system32", 1) > 0)
f2 = CreateObject("Scripting.FileSystemObject").FolderExists("C:\Windows\SysWOW64")
If f1 And f2 Then
Dim wsh
Set wsh = CreateObject("WScript.Shell")
wsh.CurrentDirectory = "C:\Windows\SysWOW64"
'keep possible command line arguments
For Each arg In WScript.Arguments
If InStr( arg, " " ) Then arg = """" & arg & """"
s = s & " " & arg
Next
wsh.Run "wscript.exe """ & WScript.ScriptFullName & """" & s, 1, False
WScript.Quit
End If
'test: show that actually the 32 bit version of wscript is now running
MsgBox WScript.FullName
'script code referencing 32 bit DLLs goes here
'(...)
Keine Kommentare:
Kommentar veröffentlichen