I have a powershell script that I want to run on my PC every time I log on. I've added it as a REG_SZ in my current user "run" key, but it never executes.

I've altered the execution policy to "unrestricted", but still no luck.

The contents of the registry value are like this:

powershell.exe c:\path\myscript.ps1

That does work from the command prompt. Any idea why it won't run from the registry?


  • Yes, I mean the startup folder, I'm sorry for that, my system is in german. Why do you think this won't work? Editing the registry is a bit more complicated because not everything is what it looks like. – Michael K May 17 '11 at 12:11
  • No probs about the language. As I say, startup may work, but I'd really like to know why the registry doesn't. – Kieran Walsh May 17 '11 at 12:41

I usually run PowerShell scripts this way:

powershell.exe -file c:\path\myscript.ps1

For more information, run this from the command line:

powershell.exe -help
  • I'll have a look at that but my command above does work from the command prompt. Thanks – Kieran Walsh May 17 '11 at 14:57
  • This does work if you change the execution policy to remote signed. Still have no idea why you need to change that or use the "-file" switch. Thanks for your help. – Kieran Walsh Aug 15 '11 at 20:02

Today I read about a powershell script that continues after rebooting the computer. To do this, the scripter automatically writes to his run-key. If you take a look at this blogpost, you'll see that he just writes the scriptname plus its params to the registry key.

I wasn't able to test it yet, but if it's worked for him, that would mean, that you don't append "powershell.exe" in front of the scriptname.

  • Thanks, that does run it - but only by opening it in Notepad - doesn't actually run the script. At least I now know it is being accessed for sure :) – Kieran Walsh Jul 20 '11 at 19:39
  • Then you might have a look at this technet-question. There is said that the easiest way to start a script is through a batch-file. Another problem could be the restriction-policy. You could also try to start your powershell-script like in the second proposal from jrich by appending '-executionpolicy unrestricted' to the powershell argument list. – wullxz Jul 22 '11 at 7:40
  • Forgot that: I don't know if the changed executionpolicy is valid only for this powershell-session that is started from the registry (can't test it right now). You have to test it and propably reset the policy to "restricted" in your script. – wullxz Jul 22 '11 at 7:43

Ok, I got this solved. You need to set the execution policy to remotesigned and not "bypass" as Microsoft told me. To do that run this command in powershell:

set-executionpolicy remotesigned

Then this is the REG_SZ in my registry run key

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -file c:\path\myscript.ps1

So now I have a powershell script that starts all my usual programs with a gap between them allowing me to get working on my machine immediately without the slowness every application trying to open at the same time.

Here is a little snippit of my *.PS1 file as others may find it useful:

# Chrome Browser
Start-Sleep -s 20
& "C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe"

# Outlook
Start-Sleep -s 10
& "c:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE"

# Messenger
Start-Sleep -s 10
& "c:\Program Files (x86)\Windows Live\Messenger\msnmsgr.exe" /background

# Snagit
Start-Sleep -s 30
& "C:\Program Files (x86)\TechSmith\Snagit 10\Snagit32.exe" /i /h

# Evernote
Start-Sleep -s 60
& "C:\Program Files (x86)\Evernote\Evernote\EvernoteTray.exe"

If I remember right you can't execute a powershell script directly (as in double clicking it), it has to be executed from the command line. Maybe Windows sees executing from the registry as executing directly. What you could try (and I my be out on a limb here) is calling the script from a batch file and then calling the batch file from the registry.

  • You can but by default the Execution policy will not allow it. You will need to change it to allow scripts. I HIGHLY recommend you sign this script. – uSlackr May 17 '11 at 14:38
  • That's right you can't double click as it opens up for editing by default. So that is why starting with powershell.exe tells it how to open. This works from the command prompt so should work from the registry too. Cheers – Kieran Walsh May 17 '11 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.