not sure the title is entirely adequate so let me explain a little clearer. I have an existing powershell script which deletes backups of specific file types. What I want to be able to do is right click within any folder or on the destop, and run the script via a custom entry on the context menu. I know very little about programming and I'm not sure if I need another script which will:

  1. Determine the current folder
  2. Pass this value to the existing powershell script
  3. Have the powershell script process using the current directory value to detect and delete the backup files.

I think I need to create separate registry keys for HKEY_CLASSES_ROOT\DesktopBackground\Shell\ and HKEY_CLASSES_ROOT\Directory\Shell\ but I'm not sure what the keys should contain and what modifications I need to make to my script to make it run as outlined above.



I've got registry entries to open PowerShell at the current directory but they can be tweaked fairly easily to suit your purposes:

Windows Registry Editor Version 5.00

@="My PS Script"

@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -File '[ENTER FILE PATH HERE]' -[Argument] '%V'"

@="My PS Script"

@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -File '[ENTER FILE PATH HERE]' -[Argument] '%L'"

@="C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -File '[ENTER FILE PATH HERE]' -[Argument] '%V'"

You can exclude the -NoExit switch if you want it to close afterwards, and obviously you will need to swap in your desired shell menu names and the script path.

Paste into Notepad, save as a .reg file and away you go!

The first and second keys deal with right clicking the background of any standard directory. The third and fourth keys deal with right clicking on a folder, and the fifth key works in library folders (such as Documents or Music - I don't know why these are different. I also don't know why this one doesn't require a name).

| improve this answer | |

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.