Page 1 of 1

call external .dll and access .cs methods with powershell

Posted: Thu Dec 06, 2018 9:39 am
by n1mdas
Hello,

I am creating a portable exe file that i am able to protect and license accordingly with https://www.obsidium.de/show/details/en .
Currently i am looking of ways how to show some licensing details using the C# SDK files.
Could you advise or show me a way of how to best embedded the .dll file along with the .cs file and doing this inside of Powershell? With the demo package the SDK files are shipped and can be reviewed. The idea is to load the .dll file and call the
EntryPoint = "obsGetLicenseStatus"
EntryPoint = "obsGetLicenseExpiration" etc.. within the Powershell GUI to show the license status which is read from an external license.key file.

I tried with the below but seems not possible to run at all:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/add-type?view=powershell-6
I found within the Internet the https://activedirectoryfaq.com/2016/01/use-net-code-c-and-dlls-in-powershell/ but would like to check how to proceed or do it in the best possible way?

Thanks,

Re: call external .dll and access .cs methods with powershell

Posted: Thu Dec 06, 2018 12:28 pm
by jvierra
Is the SDK dll a Net assembly. If so just load it an call it.
If it is a classic Win32 style DLL then you ill need to "P/Invoke" the calls from C# and add the generated type to PS.

See: https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Add-Type?view=powershell-5.1

You can probably more easily use C# to create a Net assembly wrapper and load that into PS.