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

发布于 2024-12-12 21:17:55 字数 626 浏览 4 评论 0原文

我不确定这对于 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 窗体应用程序中相同类型的调用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愁以何悠 2024-12-19 21:17:56

是的,您可以:

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

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

[custom.type]::method()

除了 Add-Type,您还可以使用反射:(

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

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

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

蓝礼 2024-12-19 21:17:56

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

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.

尘世孤行 2024-12-19 21:17:56

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

$AssemblyPath = "C:\SomePath\SomeLIB.dll"
$bytes = [System.IO.File]::ReadAllBytes($AssemblyPath)
[System.Reflection.Assembly]::Load($bytes)

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)
爱给你人给你 2024-12-19 21:17:56

时间:2019-03-07 标签: c#dllinfo

Add-Type -Path $dllPath
(new-object namespace.class)::Main() #Where namespace=dllnamespace, class=dllclass, Main()=dllstartvoid

.获取命名空间和类,

$types = Add-Type -Path $dllPath -PassThru
$types | ft fullname
$types

如果它不是“可执行”dll(获取/设置 dll 的东西),那么这是我所知道的最好的(与创建示例 dll 相比不需要):

https://kazunposh.wordpress.com/2012/03/19/проверка-корректного-ввода-distinguished-name-в-скри/

c# dll

Add-Type -Path $dllPath
(new-object namespace.class)::Main() #Where namespace=dllnamespace, class=dllclass, Main()=dllstartvoid

info. get namespace&classes

$types = Add-Type -Path $dllPath -PassThru
$types | ft fullname
$types

if it's not "executable" dll (something get/set dll) then this is the best that i know (not needed vs for sample dll creating):

https://kazunposh.wordpress.com/2012/03/19/проверка-корректного-ввода-distinguished-name-в-скри/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文