0

OS : Windows7 DB : Oracle 11 Enterprise Release 11.2.0.4.0 DSN: DSN created in ODBC in SYSWOW64

I have a vbs file that connect to Oracle DB and execute a query and return the result based on which I do some action.

Call db_connect(curSession, "DSN=INTDB;UID=RAKHSH;PWD=fdfg4qprd;")

strQuery="select count(*) from atmn.vc_run;"
call db_execute_query(curSession, strQuery)

intCount = db_get_rows_count_SQL(curSession, strQuery)

Public Function db_connect( byRef curSession ,DSN)
Set curSession = createobject("ADODB.Connection")
curSession.connectionstring = DSN
curSession.open

if Err.Number = 0 then
    db_connect=1
else
    db_connect=0
end If
End Function

I'm facing 2 problems:

  1. When I double click this vbs file, it shows an error of architecture mismatch. I found the below thread and when I open the CMD from syswow64 and execute the script it works fine but when I double click it shows error How do I run a VBScript in 32-bit mode on a 64-bit machine?

  2. I also need to run this from jenkin job using CSCRIPT, it shows the same message in jenkin console

I have been googling various solutions since last 2 days but unable to find any.

aschipfl
  • 33,626
  • 12
  • 54
  • 99

1 Answers1

0

Put this sub call at the top of your script:

RunAs32()

and include this sub in the

Sub RunAs32
    Set objShell = CreateObject("Wscript.Shell")
    If objShell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then 
        objShell.Run "c:\Windows\SysWow64\cscript.exe """ & WScript.ScriptFullName & """",1,False
        WScript.Quit
    End If 
End Sub 

If the cscript engine is running as a 64 bit, then the environmental variable PROCESSOR_ARCHITECTURE will be equal to AMD64, otherwise it will be x86. If it's AMD64 you can relaunch the script in another process with the 32 bit version of cscript, then exit the original script.

Keep in mind though that if you typically double click on a script to run it, that will open wscript.exe. You can check the calling engine with this line:

pcengine = LCase(Mid(WScript.FullName, InstrRev(WScript.FullName,"\")+1))

For a more complete answer to checking wscript vs cscript (and where the above line came from), check this post

Essentially you put a similar call to checkengine at the top of your script, then include the following sub:

Sub checkengine
  pcengine = LCase(Mid(WScript.FullName, InstrRev(WScript.FullName,"\")+1))
' BEGIN CALLOUT A
  If Not pcengine="cscript.exe" Then
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run "CSCRIPT.EXE """ & WScript.ScriptFullName & """"
    WScript.Quit
  End If
' END CALLOUT A
End Sub
langstrom
  • 1,652
  • 11
  • 14
  • It is not working for me. Although, point 1 is solved by mealy changing the Open with option in properties but point 2 is still a challenge. – Raheel Rao May 21 '18 at 07:10
  • Can you try changing your default script host to cscript by running this from an administrative command prompt: `cscript.exe //H:CScript` – langstrom May 21 '18 at 15:10
  • It works find on windows with 32bit CMD, using cscript.exe. I need to run this from Jenkin job now. Currently I'm using windows batch command plugin. But every time I execute the job, it is executed via 64bit CMD. – Raheel Rao May 23 '18 at 10:58