Monday, July 2, 2007

Extending Stsadm.exe with Custom Commands using the ISPStsadmCommand Interface

The configuration files that indicate to stsadm.exe which operations are available for execution are located in the 12 hive( C:\program files\common files\microsoft shared\web server extensions\12\CONFIG)
There 10 or more "stsadmcommands.customcommands.xml" xml configuration files located in the folder, where customcommands is arbitrary but must be unique. Through this naming convention for configuration files, stsadm.exe implements a pluggable architecture for declaring custom operations

The configuration file itself is a simple XML document with a <Commands/> root element containing one or more <Command/> sub-elements. These <Command/> sub-elements are where we declare custom operations and include two attributes name and class. As would be expected, the name attribute indicates the name of the operation to be executed by stsadm.exe. Note that the exact value of the name attribute will be specified by an administrator at runtime using the -o named parameter in order to execute the declared custom operation. The second attribute class specifies the class and .NET Assembly name where our classes that implement the ISPStsadmCommand interface live.


The .NET assembly containing our compiled custom operation(s) will be placed in the Global Assembly Cache (GAC) prior to runtime. This assembly contains one class for each custom stsadm.exe operation, and each of these classes must implement the ISPStsadmCommand interface. Each class that implements the ISPStsadmCommand interface is required to contain a GetHelpMessage method and a Run method. The GetHelpMessage method returns a string value containing help and usage information for the custom operation.

At runtime, the Run method will receive a StringDictionary parameter from stsadm.exe which consists of key/value pairs containing all named parameters, values and flags input from the WSS administrator. The Run method also takes an out type parameter which will be echoed back to the console window upon execution of the custom operation.

After writing a console application and placing the config info in the xml files, you can invoke the new command prompt.

No comments:

Post a Comment