使用PowerShell运行我的第三方DLL文件

问题描述 投票:25回答:3

我不确定PowerShell是否可行。

但基本上我有一个Windows Forms程序,配置一个名为EO Server的程序。 EO服务器有一个API,我引用了EOServerAPI.dll来运行以下代码。

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");
}

是否可以与API DLL文件交互并进行与Windows窗体应用程序中相同类型的调用?

powershell powershell-v2.0 powershell-remoting
3个回答
34
投票

是的你可以:

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

你可以像这样调用静态方法:

[custom.type]::method()

您也可以使用反射代替Add-Type:

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

(注意,即使上面调用Reflection库和LoadFile静态方法。)


11
投票

看一下Load a Custom DLL from PowerShell博客文章。如果您可以在.NET中与对象进行交互,那么您也可以在PowerShell中进行交互。


0
投票

实际上其他提供的解决方案对我来说不起作用,这里它是一个适合我的替代方案:

$AssemblyPath = "C:\SomePath\SomeLIB.dll"
$bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
[System.Reflection.Assembly]::Load($bytes)
© www.soinside.com 2019 - 2024. All rights reserved.