3

I need to call or at least pass parameters into C# function from within VBScript function (or suitable workaround) on Microsoft Azure Website Hosting i.e.:

Function VBScriptFnc(param_1, param_2, param_3)

  Dim flag;

  flag = 1

    'call the C# function or somehow pass parameters into C# function'
    csharpFunction(param_1, param_2, param_3)


  VBScriptFnc = flag

End Function
Milan
  • 3,209
  • 1
  • 35
  • 46
  • I think you'll need to compile the C# code into an assembly, and then call the method through the .dll, similar to: http://www.codeproject.com/Articles/79314/How-to-call-a-NET-DLL-from-a-VBScript – Rufus L Dec 02 '14 at 22:18
  • ..yes, except that is not so simple (registering DLL) when you are on the basic Azure hosting level. Is there any easier option ? I could always POST the values into the C# script but that seems atrocious. – Milan Dec 02 '14 at 22:22
  • Not sure what you mean by 'C# script'. C# is a managed language that has to be compiled and built in order to use it. I must be missing something... – Rufus L Dec 02 '14 at 22:30
  • I see. The situation is as follows. There is one VBScript website and one C# website (both belong to the same project). The files for both applications are in the same root. I would like to call the C# function specified in one of the .aspx file from the VBScript function specified in the .asp file. – Milan Dec 02 '14 at 22:36
  • BTW posting the parameter values from VBS into the C# script is not a good idea. Also Azure limits the size of POST / GET values to approx 1600 chars. – Milan Dec 05 '14 at 18:34

2 Answers2

5

VBScript has 5 windows into the .NET world:

  1. By doing HTTP POST/GET to a .NET handler of some kind (such as a .aspx, HTTP handler, MVC or WebAPI controller).
  2. By writing data to a file or a database for a .NET process to pick up.
  3. By exposing a .NET assembly (class library) as a COM object and adding the appropriate entries in the Windows Registry (either manually or using command utilities) so it can be called directly from VBScript. See this article.
  4. Making an executable file with .NET that is run directly from VBScript.
  5. Using PowerShell to call into a .NET assembly and using VBScript to call PowerShell.

The most straightforward option on a website is to use a GET or POST because you will steer clear of the mine fields of ACL and COM registration, but if you must go down another road I would say that PowerShell is your best bet, followed by COM interop as a third choice.

Community
  • 1
  • 1
NightOwl888
  • 55,572
  • 24
  • 139
  • 212
1

You need to mark your assembly as COM visible by setting the COMVisibleAttribute to true (either at assembly level or at class level if you want to expose only a single type).

Next you register it with:

regasm /codebase MyAssembly.dll

and finally call it from VBScript:

dim myObj
Set myObj = CreateObject("MyNamespace.MyObject")

This Answer Originally Posted By Darin Dimitrov Here.

Community
  • 1
  • 1
sam stone
  • 703
  • 5
  • 16