Windows Powershell 似乎不接受带有空格的目标路径

Gho*_*llo 16 windows powershell

我正在关注这个线程是否有一个 Win7 快捷方式可以将鼠标定位在主屏幕的中心?

按照有 12 个赞成票的人的建议,我创建了一个快捷方式,目标文件为

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned "C:\Program Files\My Scripts\CenterCursor"

它只是不起作用,除非目标文件在双引号内没有任何空格

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned "C:\Users\TOSHIBA\Desktop\CenterCursor"

这只是一个小问题,但有什么办法可以解决这个问题吗?

Yas*_*ass 16

这对我有用:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned C:\Program Files\My` Scripts\CenterCursor

请注意,您需要`在每个单词之后(在空格之前),并且不需要外部".

来源


小智 9

在更一般的情况下,您可以使用以下语法来运行路径中有空格的任何 PowerShell 脚本:

&("C:\any path with spaces in it\")
Run Code Online (Sandbox Code Playgroud)

在你的情况下,那将是:

&("C:\Program Files\My Scripts\CenterCursor")
Run Code Online (Sandbox Code Playgroud)

编辑:这仅在您使用 windows powershell 时有效

来源