下面的快捷方式执行 powershell.exe 并向其传递脚本 vscode.ps1。它的工作原理是,对于我的所有尝试,它在运行时仍然会短暂显示一个终端窗口。您可以看到我已经传递了应该防止这种情况发生的参数,但我仍然看到该窗口。我需要做什么才能从快捷方式执行 PS 脚本而不显示终端窗口?
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nologo -NoProfile -WindowStyle Hidden -file C:\Users\bernie\OneDrive\PowerShell\vscode.ps1 C:\Users\bernie\OneDrive\Documents\windows.txt
这是一个已知问题,请参阅https://github.com/PowerShell/PowerShell/issues/3028#issuecomment-583834582
正如 @Ciantic 提到的,解决此问题的最佳方法是使用 VB 脚本:
In, say ps-run.vbs
put
Set objShell = CreateObject("Wscript.Shell")
Set args = Wscript.Arguments
For Each arg In args
objShell.Run("powershell -windowstyle hidden -executionpolicy bypass -noninteractive ""&"" ""'" & arg & "'"""),0
Next
然后用它来运行你想要的命令,例如
wscript "C:\Path\To\ps-run.vbs" "C:\Other\Path\To\your-script.ps1"
我经常使用这样的东西来运行任务,而不会看到任何闪烁的窗口。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)