Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a vbs Sub from C#

Tags:

c#

vbscript

Is it possible to execute a specific sub in a vbs file from a c# application?

I have looked at creating a Process and then launching it but can not find a way to specify which particular sub in the script file should be executed. Is there a way to specify this or is there a better way of doing it?

A vbs could look something like the sample below. What I want is from the C# code to launch either test1 or test2.

Public Sub test1
    msgbox "Hey1"
End Sub

Public Sub test2
    msgbox "Hey2"
End Sub
like image 703
Mikael Avatar asked Nov 05 '22 15:11

Mikael


1 Answers

When using Visual Basic (without the .Net) I used the Script Control for this.

This page contains some documentation how to call it from good old VB.

Syntax looks something like this:

  Result = ScriptControl.Run("Name", arg1, arg2, ... argn)

Edit (after reading comment): If you do not need the VBScript to run in your context (if you do not share objects), you could create a small application that runs the script out-of-process. Your main app is 64 bit, the helper app is 32-bit. You can still pass simple parameters.

like image 50
GvS Avatar answered Nov 15 '22 06:11

GvS