在后台运行exe

Thi*_*son 2 powershell

我尝试过以下方法:

Start-Process powershell -ArgumentList "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle hidden
Run Code Online (Sandbox Code Playgroud)
Invoke-Command -ComputerName . -AsJob -ScriptBlock {
    'C:\Program Files\Prometheus.io\prometheus.exe'
}
Run Code Online (Sandbox Code Playgroud)
Start-Job -Name "prometheus" -ScriptBlock {Get-Process prometheus.io}
Run Code Online (Sandbox Code Playgroud)
Start-Job {& .\prometheus.exe}
Run Code Online (Sandbox Code Playgroud)

有时它会启动但在启动后立即终止.如果我手动启动它可以正常工作.

如何在后台保持我的进程存活?


编辑:

它没有用,因为我不在我的进程目录中,需要一个没有设置pathfile的文件.

Jam*_* C. 6

您的Start-Process语法错误,您不需要引用powershell,只需使用WindowStyleparam set 启动您的程序

Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WindowStyle Hidden
Run Code Online (Sandbox Code Playgroud)

WorkingDirectoryPARAM也可用于在特定目录来启动程序

Start-Process "C:\Program Files\Prometheus.io\prometheus.exe" -WorkingDirectory "C:\Program Files\Prometheus.io" -WindowStyle Hidden
Run Code Online (Sandbox Code Playgroud)