Reputation: 2994
Running a script in C:\Users\Ooker\Desktop
is fine, but yields error in C:\Users\Ooker\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
.
I guess it's because of Start Menu
have space in between, but I don't know how to double click the file and make it run. There seems to have no way to bracket the path beforehand.
I can run it in CLI, and it doesn't reference itself.
Upvotes: 1
Views: 2123
Reputation: 4020
Few ways to do it.
Registry: Edit your reg key at
HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command
to
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noLogo -ExecutionPolicy unrestricted -file "%1"
or
Shortcut: Create a shortcut with the target:
powershell.exe -command "& 'C:\Users\Ooker\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\MyScript.ps1'"
keep in mind that the opening in a notepad is a safety measure in the event you accidentally run it when it is not intended.
Upvotes: 2