1

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.

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Is there a way to tell it to run it in a specific file, and the rest is just opening in notepad?
@Ooker - place the file in a location of your choice and create a shortcut in the start menu (eg: powershell.exe -file 'C:\Users\Ooker\Desktop\MyScript.ps1'). It will run the file on startup as you want and other files will act as normal.
@JamesC. it seems like the only way to do so is to create shortcut. Anyway, what is the different between -file flag and -command flag in your and Drew's version? Why should Drew's version have & before the path?
The & is a call operator and will run the script you point at it. Effectively the command will launch powershell and launch the script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.