Run my third-party DLL file with PowerShell

前端 未结 3 392
死守一世寂寞
死守一世寂寞 2020-12-13 13:56

I am not sure if this is possible or not with PowerShell.

But basically I have a Windows Forms program that configures a program called EO Server. The EO Server has

相关标签:
3条回答
  • 2020-12-13 14:21

    Take a look at the blog post Load a Custom DLL from PowerShell. If you can interact with an object in .NET, you can probably do it in PowerShell too.

    0 讨论(0)
  • 2020-12-13 14:31

    Yes, you can:

    Add-Type -Path $customDll
    $a = new-object custom.type
    

    You call a static method like so:

    [custom.type]::method()
    

    Instead of Add-Type, you can also use reflection:

    [Reflection.Assembly]::LoadFile($customDll)
    

    (Note that even the above is calling the Reflection library and the LoadFile static method.)

    0 讨论(0)
  • 2020-12-13 14:44

    Actually the other offered solutions don't work for me, here it's an alternative that works perfectly for me:

    $AssemblyPath = "C:\SomePath\SomeLIB.dll"
    $bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
    [System.Reflection.Assembly]::Load($bytes)
    
    0 讨论(0)
提交回复
热议问题