如何在runonce-Key中运行powershell脚本?

Eri*_*rik 5 powershell runonce windows-7

我有一个看起来像这样的powershell.exe,它可以从我的命令行运行:

powershell.exe -noexit -command " & 'C:\Test\test.ps1' "
Run Code Online (Sandbox Code Playgroud)

但是,当我在当前用户的runonce-key中完全按照那种方式输入该条目时,没有任何反应.

从runonce调用powershell.exe传递参数或运行的正确方法是什么?

CB.*_*CB. 7

尝试使用完整路径:

c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit "C:\Test\test.ps1" 
Run Code Online (Sandbox Code Playgroud)

要么

c:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command " & 'C:\Test\test.ps1' " 
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,这是路径的一个问题,它在命令空间中工作,因为我猜想powershell路径在我的环境设置中已经登录,但是当执行runonce-key时还没有.但是,我使路径更通用:%WINDIR%\ system32\WindowsPowerShell\v1.0\powershell.exe,并在将该路径从另一个PowerShell脚本添加到注册表之前使用ExpandEnvironmentStrings.这对Win7 x64也有用吗? (2认同)