【问题标题】:Powershell - Continue a script after exiting an applicationPowershell - 退出应用程序后继续执行脚本
【发布时间】:2020-06-02 15:38:36
【问题描述】:

我对 Powershell 很陌生。 为了能够运行某个程序,我需要禁用设备。 这并不难,我创建了以下内容:

$DeviceID = (Get-PnpDevice -FriendlyName "*Devicename*").InstanceId
Disable-PnpDevice "$DeviceID" -Confirm:$false
& 'path\file.exe'

到目前为止一切顺利。但是现在我想在退出程序后启用设备。 如何让脚本看到我结束了程序?

【问题讨论】:

    标签: powershell


    【解决方案1】:

    尝试捕获结果:

    & 'path\file.exe' 2>&1
    

    然后测试应该保存在环境变量中的退出代码

    $LASTEXITCODE
    

    【讨论】:

    • 我没有得到退出代码,但我在探索这个选项时发现了一些其他选项。感谢您让我重回正轨。
    猜你喜欢
    • 2016-08-19
    • 2012-07-02
    • 2021-05-24
    • 1970-01-01
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    相关资源
    最近更新 更多