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

Mic*_*mol 26 powershell powershell-2.0 powershell-remoting

我不确定PowerShell是否可行.

但基本上我有一个Windows窗体程序来配置一个名为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");
}
Run Code Online (Sandbox Code Playgroud)

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

man*_*lds 35

是的你可以:

Add-Type -Path $customDll
$a = new-object custom.type
Run Code Online (Sandbox Code Playgroud)

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

[custom.type]::method()
Run Code Online (Sandbox Code Playgroud)

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

[Reflection.Assembly]::LoadFile($customDll)
Run Code Online (Sandbox Code Playgroud)

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


Chr*_*s N 11

看一下博客文章从PowerShell加载自定义DLL.如果您可以在.NET中与对象进行交互,那么您也可以在PowerShell中进行交互.