programing

PowerShell로 타사 DLL 파일 실행

lastcode 2023. 10. 19. 22:21
반응형

PowerShell로 타사 DLL 파일 실행

파워쉘로 가능한지 아닌지 잘 모르겠습니다.

하지만 기본적으로 저는 EO Server라는 프로그램을 구성하는 Windows Forms 프로그램을 가지고 있습니다.EO Server는 API를 가지고 있고, 나는 EOSserver API.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 Forms 응용 프로그램과 동일한 유형의 호출을 수행할 수 있습니까?

예, 가능합니다.

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

정적 방법을 다음과 같이 부릅니다.

[custom.type]::method()

Add-Type 대신 reflection을 사용할 수도 있습니다.

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

(위의 내용에서도 Reflection 라이브러리와 LoadFile 정적 메서드를 호출하고 있습니다.)

Load a Custom DLL from PowerShell 블로그 게시물을 확인합니다.의 개체와 상호 작용할 수 있는 경우.NET, 파워쉘에서도 할 수 있을 겁니다.

실제로 제공되는 다른 솔루션은 제게 적합하지 않습니다. 여기에 완벽하게 적용되는 대안이 있습니다.

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

c# dll

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

info. 네임스페이스 가져오기&

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

executable dll(something get/set dll)이 아닌 경우 이는 내가 아는 최선의 방법입니다(필요하지 않음 vs 샘플 dll 생성).

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

언급URL : https://stackoverflow.com/questions/7972141/run-my-third-party-dll-file-with-powershell

반응형