Adding Powershell command to right click menu both on and in a folder

5

4

There are some solution online but most of them just add the command when you right click on the folder. I've find a solution (which work both) for Run As Administrator here. But it works just for administrator access.

SdidS

Posted 2014-01-13T12:47:27.827

Reputation: 253

Is that a question? The format of this site is question and answer. It's fine to answer your own question, but the thing above should be a question, and the answer(s) should appear below. – dangph – 2014-01-14T04:19:56.973

@dangph, It is not a question but a possible discussion about better solution to have both commands in and on a folder. I've searched and read many topics on the issue but none of them point out the Background Shell for having the command inside the folder. Many ps1 scripts simple doesn't work and so on. However, if Admins thinks this is a violation of forum rules then please move it to another topic as answer or simply delete it. However I think this thread is useful. – SdidS – 2014-01-14T13:01:36.550

that's fine, but you should pose it as a question, and then you can provide your answer to your own question below. Or if there is already an existing question, you should answer that. I'm sure you are providing useful information, but it's best to present that in the format that people will expect. – dangph – 2014-01-14T21:18:44.800

Ok thanks, I changed the post to be in Q/A form. – SdidS – 2014-01-14T22:16:43.637

Answers

7

Here is the solution:

This adds powershell to the opening window (i.e. when right click on a file)

[HKEY_CLASSES_ROOT\Directory\shell]
    1. Create a key such as "powershell" or whatever you want without space
    2. Set the default value of the key as your desired text, e.g.:"PS here dear"
    3. Create a nested key inside the "powershell" key as "command"
    4. Edit the command value by this:
        C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%L'

This adds powershell to right click menu inside the folder

[HKEY_CLASSES_ROOT\Directory\Background\shell]
    1. Create a key such as "powershell" or whatever you want withuout space
    2. Set the default value of the key as your desired text e.g "PS here dear"
    3. Create a nested key inside the "powershell" key as "command"
    4. Edit the command value by this:
        C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'

Note to %V and %L differences in the command

SdidS

Posted 2014-01-13T12:47:27.827

Reputation: 253

1You can do similar things at HKEY_CLASSES_ROOT\*\shell and utilize the %1 variable to send the highlighted filename into your script. The * key applies shell ext to all file types. – Knuckle-Dragger – 2014-01-15T16:17:05.173

3

This is SdidS's solution as a regedit file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here]
@="PowerShell Here"

[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'"

Wilhem Meignan

Posted 2014-01-13T12:47:27.827

Reputation: 131