I wrote a DLL in .NET and I want to access it in VBScript. I don't want to add it to the assembly directory.
Is there a way to point too the DLL and create an instance of it?
I wrote a DLL in .NET and I want to access it in VBScript. I don't want to add it to the assembly directory.
Is there a way to point too the DLL and create an instance of it?
I just had to do this myself, my findings were:
Making types visible to COM:
Ensure you have the following set on your assembly - typically in AssemblyInfo.cs
After building your DLL, from SDK command line run:
This should respond:
If you get
then you need to set
ComVisible
or have no public, non-static types.From PowerShell
From vbs
Not directly. You'll need a COM Callable Wrapper to any .NET library you'll calling from COM (and hence, VBScript). Therefore, you should either directly create a CCW to the DLL or you can create a CCW for a proxy DLL which provides generic methods to load a .NET DLL and provide methods for you that call the actual methods on the component and return the result. It's really not clean at all. So, in general, the answer is no.
huseyint's answer was on the money, however, I wanted to add a little to it. Here is some sample code I used for this very issue, perhaps it can speed you along...
I had included an IsAlive method in the dll...
...and could check that it registered correctly using the syntax:
Hope this helps someone...
You can register that .NET dll with regasm utility by specifying
/codebase
parameter. This parameter is not encouraged to use with unsigned assemblies but it works when you can not put your assembly into GAC.Please note that you should not change your .dll's path after this operation since it inserts this path into the Windows registry.
In case someone needs to debug/step-into the .Net dll that's called from VBScript only:
On the .Net dll project debug setup screen, set the "start external program" by browsing to the wscript.exe program (located in C:\WINDOWS\system32\wscript.exe).
On the "Command Line Arguments", set the file name and path location of the VBScript file (C:\Test\myTest.vbs). Make sure the vbs file and dll file are in the same location.
Finally, in the .Net project DLL source code just set the break point and hit the "start debug"