加载程序集并作为进程启动它

问题描述 投票:0回答:0

如何启动程序集(exe)作为临时进程/线程,然后在任务完成时停止进程?需要但不需要输出到命令行。 在命令行中仅运行 .exe 时,一切正常,但在 powershell 中启动时,程序可以运行,但不正确。

$Path = "c:\task.exe"
$bytes = [System.IO.File]::ReadAllBytes($Path)
$assembly = [System.Reflection.Assembly]::Load($bytes)
$entryPointMethod = $assembly.GetTypes().Where({ $_.Name -eq 'Program' }, 'First').GetMethod('Main', [Reflection.BindingFlags] 'Static, Public, NonPublic')
$entryPointMethod.Invoke($null, (, [string[]] ('--archive')))
powershell process .net-assembly
© www.soinside.com 2019 - 2024. All rights reserved.