Access a custom .NET DLL in VBScript

前端 未结 5 1044
耶瑟儿~
耶瑟儿~ 2020-12-14 13:09

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 inst

5条回答
  •  一向
    一向 (楼主)
    2020-12-14 13:35

    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...

    // bind a variabe to WScript.Shell
    Set WshShell = CreateObject("WScript.Shell")
    
    // define the path to the regasm.exe file
    RegAsmPath = "c:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe"
    
    // register the dll
    WshShell.run "cmd /c " & RegAsmPath & " c:\temp\cbsecurity.dll /codebase /nologo /s", 0, True
    
    // bind a variable to the dll
    Set cbUtil = CreateObject("CBSecurity.Utilities")
    

    I had included an IsAlive method in the dll...

    Public Function IsAlive() As Boolean
        Return True
    End Function
    

    ...and could check that it registered correctly using the syntax:

    //check if dll is available to your code
    msgbox "cbUtil is alive: " & cbUtil.IsAlive
    

    Hope this helps someone...

提交回复
热议问题