0

Question:

What free or commercial scripting host for C# can run VBScript in a C# app targeting a 64 bit architecture?

Background:

It is Q3 2017 - this subject has been raised many times before but with few conclusions and many of those older code samples no longer work.

I am migrating a legacy vb6 COM dll to c# service (Dot Net framework 4.6.1+). A feature of the vb6 dll was extensibility via the MS Scripting control (msscript.ocx). This allowed the users to write small VB sripts to modify the behaviour of the application within strict constraints. It has worked well so lets not get into justifying it.

The new c# service must be a 64 bit application. msscript.ocx is 32 bit AFAIK. Ideally we will replace use of msscript.ocx with as little fuss as possible.

Notes:

  1. Powershell is probably not a good replacement candidate as it would give users access to a Pandoras box of capabilities.
  2. I have seen reference to codefluent client as a potential direct replacement but cannot find sample code. Is this product supported for vbscript?
  3. Executing the vbscript as a file via some shell approach is not considered viable because the script must be able to callback to the C# host to ask for variables.
  4. ActiveXScriptLib is a potential. It has a NuGet package that installs via VisualStudio, and the examples given here work for me in x64, including the more complicated example of having the script access nominated methods of the hosting c#.

Research notes:

This has been a well-trodden path since MS introduced the first 64 bit OS, however much of the sample code no longer runs in current C#.

Sample code

As a temp fix, can anyone provide sample code to be used in a C# 64 bit app that can utilise msscript.ocx? This sample 'would' work if the msscript.ocx was accessible - I get the error:

System.Runtime.InteropServices.COMException: 'Retrieving the COM class factory for component with CLSID {0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).'

public void TestScript()
{
    Type scriptType = Type.GetTypeFromCLSID(Guid.Parse("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"));
    dynamic obj = Activator.CreateInstance(scriptType, false);
    obj.Language = "vbscript";
    string vbscript = "2 * 2";
    var res = obj.Eval(vbscript);
    System.Diagnostics.Trace.WriteLine(res);
}

Edit: See item 4 added to list in notes - showing some potential.

Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67
  • 2
    Microsoft's [ClearScript](https://github.com/Microsoft/ClearScript) is what you're looking for. – Kul-Tigin Oct 05 '17 at 05:21
  • Thanks @Kul-Tigin - had a look at the link and see that it is an active project with recent commits so looking good so far. Also supports VBScript so another plus. – Vanquished Wombat Oct 05 '17 at 12:13

1 Answers1

1

Since you mentionned CodeFluent Entities in your question, yes it supports VBScript. You can have a look at this previous entry from stackoverflow for quite advanced scenarios codefluent-vs-interop-msscriptcontrol-dll or a quite simpler sample from this blog entry, also mentionning where to get this Codefluent Runtime Client from nuget.

MCR
  • 79
  • 1