Microsoft have opened up stsadm.exe for use by third party developers. This has been done to make managing a SharePoint server easier for a administrator, by giving them a one stop tool to configure applications that are built on top of SharePoint (MOSS an WSS).
To add your command to stsadm you need to:
1. Create a file xml file in the C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG directory with the prefix of stsadmcommands. For example stsadmcommands.customapp.xml
2. This file has a root node called Commands and child node Command with both name and class as attributes. The name attribute contains the command which will be exposed via stsadm, and the class attribute contains a full qualified reference to you assembly.
For an example of the xml look at the out of the box command xml files in the directory.
3. Next is to create a class (and assembly) which you command will load and excute. Create a new class in your visual studio solution and call it stscommands (any name will do), next add a reference to Microsoft.SharePoint.StsAdmin found in the Microsoft.SharePoint assembly. Then set your class to implement the interface ISPStsadmCommand
C# Example
public class stscommands:ISPStsadmCommand
{
public string GetHelpMessage(string command){}
public int Run(string command, System.Collections.Specialized.StringDictionary keyValues, out string output){}
}
4. Populate out the methods and deploy your assembly to the GAC
5. You can now run stsadm.exe and will see you command appear in the list of available commands.
Parameters are automatically process and passed into you custom command class and are access via the keyValues parameter, for example:
C# Example
Console.WriteLine(keyValues[“MyCustParam”]);
This is process of extending stsadm is very useful if your project/application has any configuration setting that need set prior to your code being used. Also if you deploy your assembly and xml configuration file via a SharePoint deployment solution it will be automatically deployed to all servers in your farm.