Scripting in 32/64Bits
-
Wednesday, August 29, 2012 9:09 AM
Hi all,
I have to use a script (I don't care the language, but it must be "writable" by the program) in a VB.NET project.
This script have to access to the ODBC. I have two different DB engine, one reachable into a 32bit ODBC, one reachable into a 64bit ODBC.I know that windows 64bit environment can run 64bit scripts:
-
I tryed to write this script:
Function ExecuteSelect(ConnectionString, SqlStr)
Dim Conn, RecSet
Set Conn = CreateObject("ADODB.Connection")
Conn.ConnectionString = ConnectionString
Conn.Open()
Set RecSet = Conn.Execute(SqlStr)
If RecSet.BOF And RecSet.EOF Then
ExecuteSelect = "#NotFound#"
Else
RecSet.MoveFirst()
If IsNull(RecSet(0)) Then
ExecuteSelect = "#Null#"
Else
ExecuteSelect = RecSet(0)
End If
End If
RecSet.Close
Set RecSet = Nothing
Conn.Close
Set Conn = Nothing
End FunctionThere is the way to run this script into 32 or 64 bit mode: If I write into it another line like this:
MsgBox ExecuteSelect("DSN=DBConn;UID=***;PWD=***;", "Select Count(*) From sysobjects")
and I run it by the command
c:\Windows\SysWow64\WScript ExecuteSelect.vbs
It Returns the number of rows into the table on DB accessing throug the 32 bit.
If I change the DSNwith the 64 bit one and I run it by the command
C:\Windows\System32\WScript ExecuteSelect.vbs
It returns the number of rows into the table on DB accessing throug the 64 bit.
And If I don't change the DSN, WScript returns invalid architecture correspondance between the application and the driver.
Ok, There is a way to execute VBScript into 32 or into 64 bit shell. How to do it into a VB.NET?
I tryed to use msscript.ocx, and I can access to the 32 bit ODBC (if I compile my application in x86 mode), but not to the 64 one!
I googled a bit and I found some methods (using DTS, iActiveScriptParser, or someting more), but I cannot reach the way to access to DTS from VBNet (it says the COM is not valid) or iActiveScriptParser (I didn't found the dll, api reference, or some else, neither how to write the methods the interface has).
Someone can tell me a way to evaluate a script function step by step?
- Moved by Mark Liu-lxfModerator Thursday, August 30, 2012 3:08 AM (From:Visual Basic Interop and Upgrade)
- Edited by Lucio Menci Thursday, August 30, 2012 11:17 AM clarify the argument
- Moved by Bill_StewartMicrosoft Community Contributor Thursday, August 30, 2012 4:24 PM Moving back to correct forum (From:The Official Scripting Guys Forum!)
-
All Replies
-
Thursday, August 30, 2012 3:07 AMModerator
Hi Lucio,
Welcome to the MSDN forum.
This Queue is for VB.Net. Your topic about VB script is out of scope here. For better support, I will move this thread to The Official Scripting Guys Forum. It will cost a little time to involve the members in this forum. I appreciate your patience.
Sorry for any inconvenience and have a nice day.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
-
Thursday, August 30, 2012 11:14 AM
I wrote the post here because the post is about VB.Net (how to manage scripts in VB.Net 64bit)
I started to talk about scripts because I know Win64 can execute scripts in 64 bits, but I didn't found anything about the execution of scripts in 64 bits by Vb.Net
-
Thursday, August 30, 2012 12:36 PMSorry, but you are being bounced around a bit here. We can't answer your question. This forum is for VBS and Powershell and Cmd. Not VB.Net. There is no direct translation from VBS to VB.Net. They are completely different languages.
Grant Ward, a.k.a. Bigteddy
- Edited by BigteddyMicrosoft Community Contributor Thursday, August 30, 2012 12:37 PM
-
Thursday, August 30, 2012 3:32 PM
The question is how to host a VBScript in a VB.NET application.
The ActiveX control (msscript.ocx) can do this. It cannot do i in a 64 bit session but there may be a way to force it.
In any cas4e the question is for VB.NET and not a scripting question.
The question is "How can I host msscript.ocx in a VB.NET form?" and should be posted in teh Visual Studio forum for the version of VS being used.
Maybe later I will try to remember how I fif it a number of years ago. It is not very hard to do as I remember.
Anyway change the question and move this to the Visual Studio forum as somone there may have the answer immediately.
Remember that an OCX is untrusted code.
¯\_(ツ)_/¯
-
Thursday, August 30, 2012 4:57 PM
Interesting move. Yes Interop might be a solution but I don't think so.
Look into the scripting SDK for complete documentaion on how to embed a scrip engine in an application.
http://www.microsoft.com/msj/1099/visualprog/visualprog1099.aspx
¯\_(ツ)_/¯
-
Friday, August 31, 2012 10:21 AM
Hi,
Thank you so much!Maybe I am one step below to the result I want, but I need a little boost ( :-) ).
I tried to translte from C++ to VB.Net some of the rows into the c++ source code:
Dim scriptSite As New SCRIPTCONTROLSVRLib.ScriptControl
scriptSite.initscriptengine(Nothing)
scriptSite.LoadScript("Function MyTry" & vbCrLf &
" MsgBox ""MyTry""" & vbCrLf &
"End Function")
scriptSite.Connect()
scriptSite.RunMacro("MyTry")1: The first statement (scriptSite initialization) runs well (if I check for scriptsite value IDE tells me it has an instance of the class), but all other statements return public member 'xxxx' not found.
2: I wasn't able to translate the following rows:
hResult = CLSIDFromProgID( L"VBScript", &clsid );
HRESULT hr = scriptSite.InitScriptEngine(clsid);
3: I didn't see how pass parameters in function and how to retrieve the result. It would seem that you can do only:
scriptSite.RunMacro("MacroName")
and it returns the execution state (OK), but not
FunResult = scriptSite.RunMacro("MacroName", new Objsct() {Param1, Param2, Param3})
like with MSScriptControl... -
Friday, August 31, 2012 7:40 PM
Try this:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim scriptSite As New MSScriptControl.ScriptControl scriptSite.Language = "vbscript" scriptSite.ExecuteStatement("MsgBox ""MyTry""") scriptSite.AddCode("Function Doit():MsgBox ""Done!"":End Function") scriptSite.ExecuteStatement("Doit") End Sub¯\_(ツ)_/¯
-
Saturday, September 01, 2012 9:09 AM
Hum.... No,
This runs only in 32 bit. I need that the vbscript accesses to the 64bit libraries (odbc)
-
Saturday, September 01, 2012 11:41 AM
Hum.... No,
This runs only in 32 bit. I need that the vbscript accesses to the 64bit libraries (odbc)
What question are you answering?
You cannot access 64 bit ADO drivers from 32 bit sessions.
Why do ytou thingk you need to use 64 bit drivers? All ADO.Net drivers are available for both 32 and 64 bit systems.
There i NO ODBC in WIndows anymore. It is an old technology. The ODBS settings are just translated to ADO. All yu need is th e Net connection class and the conenct string. YOU do not need to specify 32/64 bit. It is transparent if you use OleDB, SQLServer or Oracle although Oracle needs to have the full Oracle Net drivers instaleld. These are not installed by default with teh Oracle client.
¯\_(ツ)_/¯
-
Monday, September 03, 2012 7:38 AM
Ok, It's true, but I don't care. I need to write a vb.net application in 64 bit (because it is to be exposed for COM interoperability to a program that may be 64 bit) and it has to run vbscript code.
-
Monday, September 03, 2012 11:54 AM
Ok, It's true, but I don't care. I need to write a vb.net application in 64 bit (because it is to be exposed for COM interoperability to a program that may be 64 bit) and it has to run vbscript code.
As far a I know you cannot run 32 bit controls in a 64 bit program.
¯\_(ツ)_/¯
-
Tuesday, September 04, 2012 7:33 AM
And this is the reason why I need to run vbscript in 64 bits.
Back to the beginning:- I know that vbScript can be execute under the 64bit machine (I wrote a little script that use ADODB/ODBC where you can see that c:\Windows\System32\WSCript accesses to the ODBC opened in 64 bit and C:\Windows\SysWow64\WScript accesses to the ODBC opened in 32 bit)
- you show me that there is a way to embed VBScript engine in an application
- I found more and more of that examples, but all of them were written in C++, I tried to access to the interop created by the example but I wasn't able. (see the post sent on August 31 10:21 AM)
Can you help me?
-
Tuesday, September 04, 2012 12:35 PM
How did you create the Interop? Which library did you use?
There can be many versions of scripting libraries in a system. Many vendors produce custom versions. All are based on pretty much the same source code.
What DLL did you use and where are the examples that you are using.
¯\_(ツ)_/¯
-
Wednesday, September 05, 2012 8:53 AM
The example you show to me the august 30
http://www.microsoft.com/msj/1099/visualprog/visualprog1099.aspx
There is a link to a zip where there are the examples how make a dll and how use it in C++. I try to use the dll and the tlb that the client uses.
There are two folders: the first show how make a script server (scriptcontrolsrv) and how use it. The second one (userscriptcontrol) shows how to embed all into a single application.
The first one makes an application that is connected to the dll (or the tlb, there are both, and I didn't understand wich uses), and uses it to evaluate some VBScript functions. I tried to connect to the same dll (and to the same tlb), but I found the problems shown the August 31.
I have to apologize if I'm too pushy, I tried also to contact Shepherd, but the mail address I found not longer exists.
Thank you -
Wednesday, September 05, 2012 1:30 PM
Ok but where did you find the 64 bit libraries to use to build this? You need the hosting library 64 bit version.
¯\_(ツ)_/¯
-
Wednesday, September 05, 2012 1:58 PM
Ouch! I hoped that it was anycpu! We found another impasse. But I know that VBScript can be execute in 64 bits:
VBScript in 32bit snapshot
VBScript in 64bit shapshotIt seems odd that Windows can host VBScript in 64-bit, when any .Net tools can.
-
Wednesday, September 05, 2012 2:13 PM
You must build explicitly for 64 bits. You must build the server is C++.
I do not think the libraries for 64 bits are available ouytside of the older SDK. I have not built this code in many years. It is a very old MFC application.
¯\_(ツ)_/¯
-
Monday, September 24, 2012 4:50 PM
Hi!
I'm a little step beyond!
See that code:
DimwebBrowser1AsNewWebBrowser
webBrowser1.ObjectForScripting= Me
webBrowser1.DocumentText= "<html>"& vbCrLf& _
"<head>"& vbCrLf& _
"<script type=""text/vbscript"">"& vbCrLf& _
"</script>"& vbCrLf& _
"</head>"& vbCrLf& _
"<body>"& vbCrLf& _
"</body>"& vbCrLf& _
"</html>".Replace("</script>", _
IO.File.ReadAllText(VBFileName) & vbCrLf& "</script>")
Application.DoEvents()
MsgBox(webBrowser1.Document.InvokeScript(MyFunctionName, ParameterArray))It's running well, until I try to execute an SQL statment. Even if it's running into a DB resident in my machine, IE returns this exception:
Safety settings on this computer prohibit accessing a data source on another domain.
I enabled this IE setting, but there is another warning:
ADO Security Warning:
The website is using your identity to access a data source. If the Web site is trustworthy, click OK to continue, or click Cancel.I don't like it. How do I say ADO that It's trusted without the user request?
-
Monday, September 24, 2012 5:05 PM
You cannot. ADO will not trust a web request. If youare writing am IIS server access then you can allow for access.
You can also use VB directly and feed the results into the WebBrowser control.
If you just want formatted output then consider using the RichTextControl. This will allow for colored and fancy tables. You can also use one of many HTML controls that do not run as a webbrowser.
The Web Browser is very highly sandboxed under all circumstances. It will not allow you free access safely without a prompt. If you cahge this then the whole machine will be vulnerable to malware.
TO test all of this create an HTML file with all of rteh code and run it as an HTA. It will work. Change the extension to HTM and it will give you the same type of error. AN HTA is allowed to run this way. An HTA cannot be embedded in an application.
¯\_(ツ)_/¯
- Marked As Answer by Lucio Menci Thursday, September 27, 2012 9:43 AM
-
Thursday, September 27, 2012 9:42 AM
DDDD OOO N N EEEEE !! III TTTTT RRRR U U N N SSS
D D O O NN N E !! I T R R U U NN N S
D D O O N N N EEE !! I T RRRR U U N N N SSS
D D O O N NN E I T R R U U N NN S
DDDD OOO N N EEEEE !! III T R R UUU N N SSSI had to load the script, generate the HTML headers, save it into a temporary file, load it by the web browser!!
Dim S As String = IO.File.ReadAllText(VbsFileName) IO.File.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Temp & "\VBS.html", "<html>" & VbCrLf & "<head>" & VbCrLf & "<script type=""text/vbscript"">" & vbCrLf & S & vbCrLf & "</script></head></html>") X.Url = New Uri(My.Computer.FileSystem.SpecialDirectories.Temp & "\VBS.html") Application.DoEvents Dim Result As Object = x.Document.InvokeScript(MyFunction, MyParameterArray)
- Edited by Lucio Menci Thursday, September 27, 2012 9:43 AM
-
Wednesday, October 24, 2012 4:05 PM
Sorry, but ADO can, among other things, use ODBC drivers. ODBC is still a supported database API, even if much less popular than it used to be.
Look under Administrative Tools, even on Win8, and you'll see "Data Sources (ODBC)"

