23

I was following this thread Is there a Win7 shortcut to position mouse in center of primary screen?

Following the suggestion of the guy with 12 upvotes, I created a shortcut with the target file being

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

It just wouldn't work, unless the target file doesn't have any spaces inside the double quote

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

It's just a minor issue but is there any way to fix this?

4 Answers 4

21

This worked for me:

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

Note that you will need a ` after each word (before the space) and you don't need the outer ".

Source

2
  • 1
    I spent ages trying to find a solution until I came across your answer. It worked perfectly. Commented Oct 18, 2016 at 9:01
  • Check out my answer for a more general case. Commented Nov 26, 2018 at 18:33
12

In a more general case, you can use the following syntax to run any PowerShell script with space in the path:

&("C:\any path with spaces in it\")

In your case, that would be:

&("C:\Program Files\My Scripts\CenterCursor")

Edit: this only works if you are using windows powershell

Source

2
  • You don't need the parentheses. Commented Oct 26, 2019 at 6:07
  • 1
    Maybe a silly question but what if the path is holded by a variable. How does the code then look? Commented Sep 1, 2022 at 19:23
3

You might be able to cheat by using the short name.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned "C:\Progra~1\MyScri~1\CenterCursor"

I guessed your short names based on likelihood, but you can find the real ones using methods from this question like dir /x.

1

Try using the single quotes instead of double quotes, it might help.

1
  • 5
    Welcome to Super User! Your answer could be improved by explaining how adding double-quotes helps, and perhaps providing an example line of code. Commented Mar 4, 2015 at 2:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.