Hello i have this code:
# Note: This must be an executable or DLL compiled for .NET
$Path = "C:\Users\sadettin\desktop\tok.exe"
# Get Base64-encoded representation of the bytes that make up the assembly.
$bytes = [System.IO.File]::ReadAllBytes($Path)
$string = [System.Convert]::ToBase64String($bytes)
# ...
# Convert the Base64-encoded string back to a byte array, load
# the byte array as an assembly, and save the object representing the
# loaded assembly for later use.
$bytes = [System.Convert]::FromBase64String($string)
$assembly = [System.Reflection.Assembly]::Load($bytes)
# Get the static method that is the executable's entry point.
# Note:
# * Assumes 'Program' as the class name,
# and a static method named 'Main' as the entry point.
# * Should there be several classes by that name, the *first*
# - public or non-public - type returned is used.
# If you know the desired type's namespace, use, e.g.
# $assembly.GetType('MyNameSpace.Program').GetMethod(...)
$entryPointMethod =
$assembly.GetTypes().Where({ $_.Name -eq 'Program' }, 'First').
GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic')
# Now you can call the entry point.
# This example passes two arguments, 'foo' and 'bar'
$entryPointMethod.Invoke($null, (, [string[]] ('foo', 'bar')))
That code works for .NET framework console projects. Somehow it doesn't work for .NET framework Form applications, And i added this:
$entryPointMethod.Invoke($null, $null)
For now, it works both console and form application versions.
But it doesn't loads when i try put another .net programs to $path i think its because of $entryPointMethod. so we need to modify it to make it worked for all programs.
Is there a way to make this system universal??? and How todo? thanks