Satya Madala
Satya Madala

Reputation: 335

How to call aspecific function in vbscript from VB.net code

From VB.net we can execute VBScript code by using following line:

System.Diagnostics.Process.start("AbsolutePathofVBScriptfile")

But how can one call a specific function present in vbscript from VB.net code? I searched for that but couldn't figure it out. Some things I found were IActiveScript, MSScript.ocx...

Upvotes: 0

Views: 2900

Answers (1)

Jonathon Reinhart
Jonathon Reinhart

Reputation: 137517

I'm not sure that this can be done, as you are operating in two totally different domains.

That line of code you present does nothing different than if you double-clicked the vbscript file.

I've done next to no vbscript programming, but what about this... Create another script file (stub) that does nothing but call a function (subroutine) in your main, library file. Then, invoke the stub from the VB.net application.

library.vbs

Function LibraryFunction(oValue)
    Wscript.Echo "LibraryRoutine Running!"
End Sub

...

stub.vbs

' Essentially "Import" the library script
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("procedures.vbs", ForReading)
Execute objFile.ReadAll()

' Call the appropriate function from library
LibraryFunction(4)

VB.net

System.Diagnostics.Process.start("stub.vbs")

Functions, Subroutines, and How to Call Them From Other Scripts

Upvotes: 2

Related Questions