3

We are using interop.msscriptcontrol.dll to execute simple VBScript variables code ("Today - 1" kind of stuff). Our application is non-COM components except for this one. We have searched for a .Net replacement of VBScript, but we've been unable to find one.

Is there a VBScripting replacement for .Net?

John Cruz
  • 1,562
  • 4
  • 14
  • 32
  • 1
    Possible duplicate with: http://stackoverflow.com/questions/320814/dotnet-version-of-windows-scripting-host – David Brabant May 06 '12 at 15:58
  • Another duplicate: http://stackoverflow.com/questions/200422/how-to-call-a-vbscript-file-in-a-c-sharp-application – Peter Ritchie May 06 '12 at 16:18
  • No, neither of those are what I'm asking. I want a way to DO VBScript in .Net without using COM. Not a new way to do scripting in general. – John Cruz May 06 '12 at 17:26
  • 1
    Yes, you are not going to find that. It is entirely unclear why you think there's something wrong with COM. If you dislike it because it is "old fashioned" then take a good look at Metro and WinRT on Windows 8. Heavily COM based at its core. – Hans Passant May 06 '12 at 17:39
  • We do not dislike COM. We've simply had a couple of potential customers question it, and we figured if there was a replacement, then great, we would use it. – John Cruz May 07 '12 at 02:43

2 Answers2

2

In the following example, I will make the WebBrowser control evaluate the VBScript expression "Now - 1" and embed the result in the WebBrowser's document.title so I can fetch it in C#:

WebBrowser wb = new WebBrowser();
wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(
    (object _sender, WebBrowserDocumentCompletedEventArgs _e) =>
    {
        MessageBox.Show(wb.Document.Title);
    }
);
wb.DocumentText = @"
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
<SCRIPT language=""VBScript"">
document.title = Now - 1
</SCRIPT>
</HEAD>
<BODY/>
</HTML>";

Obviously, this approach suffers from:

  • the results are processed as strings
  • the results require asynchronous handling
  • poor code injection can lead to invalid results
  • it may not perform well and could lead to creating a bottleneck in your app

My gut feeling is this approach is potentially worse than the approach you're currently using.

Stephen Quan
  • 21,481
  • 4
  • 88
  • 75
  • For me, this is a worse approach than using interop.msscriptcontrol.dll, BUT, you gave me a good outside-the-box answer, so I +1'd you. I may have some use for this in the future. – John Cruz May 08 '12 at 13:20
2

I ended up using the free Codefluent runtime engine to replace msscriptcontrol.dll:

http://www.softfluent.com/products/codefluent-runtime-client

John Cruz
  • 1,562
  • 4
  • 14
  • 32