http://www.perlmonks.org?node_id=277596

Note: This isn't really a Perl thing, but I'm using it for Perl scripts and it's too handy not to share.

I have a few scripts that I run frequently for work. Most parse the files in a directory and create an HTML report file. I wanted to share these with coworkers, but didn't want to have to explain the command prompt to them. My solution was going to be telling everyone to stick the .pl file in their local directory and then double-click it. (They already have Perl installed.) The problem is that we need to run these scripts in many, many directories and there are too many potential problems that can occur when you have multiple copies of the same script all over a hard drive.

I was thinking about a way to make this easier. The best idea I had was to allow them to right-click on a folder in Explorer and run the script from the context menu. I just had no idea how to do that. Thanks to Windows 98 Right Mouse Click Customisation, I was able to figure it out.

If you're interested in trying this, here are the steps.

Note: These instructions were written and tested using Windows 2000. They may be different for your version. Oh, and it's the registry, be careful in there. If you don't know the risks of editing registry keys, then don't do it.

  1. Open the Registry Editor by running regedit.
  2. Expand HKEY_CLASSES_ROOT > Directory.
  3. Right-click on shell under Directory and select New > Key.
  4. Enter a name for the script you're adding. I don't know if there are restrictions, but since this is not for display, don't use anything by letters and numbers (just to be safe).
  5. Left-click on the name you just entered. You'll see a (Default) value in the main window. Right-click on (Default) and select Modify.
  6. Enter the display name for your script in the Value data field. Click OK when you're done.
  7. Right-click on the name you entered in step 4 and select New > Key.
  8. Enter command.
  9. Click on the command folder. You'll see a (Default) value in the main window. Right-click on (Default) and select Modify.
  10. Enter the command line for your script in the Value data field. For example, perl.exe c:\work\perl\qaHelpTitles.pl. Click OK when you're done.
  11. Open an Explorer window and test by right-clicking on a folder and selecting the display name you entered.
  12. If everything worked, then close the Registry Editor. If there were problems, then you may want to verify that perl.exe is in your path or the path and filename for the script are correct. Try pasting the command line into a Command Prompt window and running it that way. If it works, then I'm not sure what went wrong here. Sorry.

Hope this helps!