Skip to main content

Cloud

Windows Explorer WSP Context Menu Commands

I am presently developing a large, complex SharePoint application whose deployment consists of about 10 SharePoint Solutions. Since functionality is still under development, I am very frequently rebuilding WSPs and upgrading them.
My standard way of doing this was via the command shell:
stsadm -o upgradesolution -name [solution name] -filename [solution path] -immediate -allowgacdeployment
Less frequently I was adding Solutions to the Solution store (using stsadm -o addsolution) and deploying those Solutions (using stsadm -o deploysolution).
Eventually I got sick of typing these commands, especially upgradesolution, which I used all the time, and I remembered that you can very easily add context menus to Windows Explorer by editing the registry. I now have my development machine set up so I can right-click any WSP in the file system and either Add to Solution Store or Upgrade Solution (Figure 1). This small change has made deployment of my SharePoint Solutions so much easier and I am more productive as a result.
WSP Context Menu Commands
Figure 1
In this article, I will explain how to set this up, so you too can stop typing commands to perform these operations.
The steps required are as follows:
  1. Edit the registry to specify the context commands you want for the .wsp file extension.
  2. Set up a batch file for each command which runs stsadm.
To add the context commands to the registry, take the following steps:
  1. Open regedit.exe and add a key HKCR.wsp
  2. Add a key subordinate to HKCR.wsp and call it shell
  3. Add a key subordinate to HKCR.wspshell and call it whatever you’d like displayed as the context menu command
  4. Add a key subordinate to HKCR.wspshell[commandName] and call it command
  5. For the Default REG_Z value, assign the command you’d like to execute when the user clicks this context menu item. My pattern is to make a batch file per command and pass the full file path as a parameter.
My Upgrade Solution command, for example, is
"C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions12BINUpgradeSolution.bat" "%1"
The quotes are important because they allow the shell to gracefully deal with file paths containing spaces. Please see Figure 2 for a picture of how this should look in RegEdit.
Configuring WSP Context Commands in the Registry
Figure 2
Now that you have your commands set up, you need to create your batch files. I chose to put mine in the 12 hive Bin folder. Yes, I know you’re thinking I shouldn’t put it there, since that is a SharePoint system folder, but it was convenient at the time and of course you can put them anywhere, so choose any location you like – just be sure your command path above is pointing to the right location.
All the batch files will consist of is an stsadm command that extracts pieces of the file path to pass as parameters to stsadm.
For the Add to Solution Store command, the batch file looks like this:
stsadm -o addsolution -filename %1
pause
Notice I am passing the full file path to stsadm as the filename parameter to AddSolution.
For the Upgrade Solution command, the batch file looks like this:
stsadm -o upgradesolution -name "%~nx1" -filename %1 -immediate -allowgacdeployment
pause
Just as with AddSolution, UpgradeSolution requires the full file path as the filename parameter. More interestingly, the name of the Solution is always just the WSP filename with extension, and the syntax %~nx1 extracts just the filename.extension portion of a full file path.
Also, notice the name parameter needs quotes surrounding it (in cases of spaces in the name) but the filename parameter does not, because those are already present in what is passed from Explorer.
You might wonder why I need a batch file at all. What can’t I just run this command by directly specifying stsadm as the value of the Default REG_SZ value in RegEdit? This does in fact work for AddSolution, where all we need is the full file path, but for UpgradeSolution it didn’t work because the %~nx1 doesn’t work in that context – only in the context of batch file processing. So although I don’t need a batch file for AddSolution, I made one anyway to set up a pattern.
By the way, there are many different operations you can perform on batch file parameters. Windows IT Pro has an informative article describing them.
There are potential enhancements to this, of course. There are commands such as DeploySolution that require other parameters (such as url) that we can’t calculate based on file path information. The associated batch file could prompt for this information, or hard code the values, in which case you’d need different commands for different content URLs. Also, you see hard coded paths to the 12 hive in my RegEdit setup, and I would prefer to use something like this:
%CommonProgramFiles%Microsoft Sharedweb server extensions12BINstsadm.exe
but I was getting permission exceptions when trying to run the command, so this is something to be cleaned up. And finally, I should probably put the batch files elsewhere in the file system.
Give this a shot if you work frequently with SharePoint Solutions. The 5 minutes of setup time will pay itself back very quickly as a result of your enhanced productivity.
I have supplied the RegEdit export below. Just make a .REG file out of this and run it to add the values to your registry. Of course, the usual disclaimers about registry operations apply – be careful, don’t do this if you don’t know what you are doing, and make a backup of your registry first in case you mess it up.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT.wsp]
@="wspfile"
[HKEY_CLASSES_ROOT.wspshell]
[HKEY_CLASSES_ROOT.wspshellAdd to Solution Store]
[HKEY_CLASSES_ROOT.wspshellAdd to Solution Storecommand]
@=""C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\AddSolution" "%1""
[HKEY_CLASSES_ROOT.wspshellUpgrade Solution]
[HKEY_CLASSES_ROOT.wspshellUpgrade Solutioncommand]
@=""C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\BIN\UpgradeSolution.bat" "%1""

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us
TwitterLinkedinFacebookYoutubeInstagram