How to call C# DLL function from VBScript

19,426

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

Solution 2

Yes you will need to set the ComVisible attribute to true and then register the assembly using regasm or regsvcs along with tlbexp. Then you can use Server.CreateObject and sail through.

Share:
19,426
abatishchev
Author by

abatishchev

This is my GUID. There are many like it but this one is mine. My GUID is my best friend. It is my life. I must master it as I must master my life. Without me, my GUID is useless. Without my GUID I am useless.

Updated on June 04, 2022

Comments

  • abatishchev
    abatishchev about 2 years

    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?

  • bluish
    bluish over 11 years
  • cheezsteak
    cheezsteak about 8 years
    Is it possible to use Dim myObj As MyNamespace.MyObject in VBScript as you can in VBA so you don't need CreateObject? Is there an explicit reference you can make?