Run my third-party DLL file with PowerShell

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 10:59:43

问题


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 an API, and I make a reference to EOServerAPI.dll to make the following code run.

using EOserverAPI;
...
private void myButton_Click(object sender, EventArgs e)
{
    String MDSConnString="Data Source=MSI;Initial Catalog=EOMDS;Integrated Security=True;";

    //Create the connection
    IEOMDSAPI myEOMDSAPI = EOMDSAPI.Create(MDSConnString);

    //Get JobID
    Guid myMasterJobID = myEOMDSAPI.GetJobID("myJobRocks");
}

Is it possible to interact with an API DLL file and make the same types of calls as you would in a Windows Forms application?


回答1:


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




回答2:


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.




回答3:


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)


来源:https://stackoverflow.com/questions/7972141/run-my-third-party-dll-file-with-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!