如何启动程序集(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')))