How to call C# DLL function from VBScript

abatishchev picture abatishchev · Apr 20, 2009 · Viewed 18.9k times · Source

I have my script on server, so I do not have UI interaction available and have to use DLL instead of console application.

How to call a function in C# DLL from VBScript?

How do I make my DLL to be COMVisible? Do I have to register it?

Answer

Darin Dimitrov picture Darin Dimitrov · Apr 20, 2009

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")