I have a Web site with about 50 virtual directories listed in order of creation. I could manage the virtual directories more easily if I could sort them alphabetically, but I haven't figured out how to do so. When I try to sort the virtual directory list in the Microsoft Management Console (MMC) Internet Information Services snap-in by selecting the Name field in the right pane, the listings remain sorted by creation date. Can you help?
You'll find that MMC behaves a bit differently depending on which version you have. All versions let you sort on the Name column in the details pane—at least sort of. In version 1.0 (Windows NT 4.0), the names are sorted alphabetically but gathered by type. In version 1.2 (tested on Windows 2000), the names are sorted alphabetically but the virtual directories are intermingled with files and regular folders.
What's stranger still is that although the Internet Information Services snap-in doesn't list virtual directories alphabetically, they appear alphabetically when you use MetaEdit to view the metabase. All this confusion aside, you can resequence your directories relatively painlessly—although the process is somewhat tedious.
Use MetaEdit 2.2 to export your metabase settings to a text file. You can then manipulate the text file to resequence the virtual directories and reimport your reorganized settings. To do so, first back up your metabase. Then, open MetaEdit and open the Root key of the Web site instance number. For example, start MetaEdit, and in the left panel, expand LM, W3SVC, then Web site instance 1 to display the Default Web Site for a default installation.
To find which of the Web site numbers is the correct one for the Web site, you can use trial and error. Select an instance, then in the right-hand pane, locate the Web site name, which is in the Data field of the metabase key with the name ServerComment. When you find the correct Web site name, you've found the Web site number. For example, Figure 2 shows that 1 is the Web site number for the Default Web Site. You can also find the Web site number through a script in the Adminscripts folder called FindWeb.vbs. If you provide FindWeb.vbs with the name of a Web site, it returns information about the site including the Web site number. On a default installation, you can type
c:\inetpub\adminscripts findWeb.vbs "Default Web Site"
at a command prompt, which would return
Web Site Number = 1 Web Site Description = Default Web Site Hostname = Port = 80 IP Address =
After you identify the Web site number, you can locate the Root key in the Web site's metabase, which Figure 2 shows. When you open this key, you see the listings for virtual directories as well as for other directories and possibly for files. With the Root key selected, as Figure 3 shows, select Metabase, Export Text File, and provide a path and a name for the text file that will contain the Root key settings.
Using Notepad, open the text file and examine the contents. Note the well-organized structure, which contains the exported Root key. You can easily identify the virtual directory definitions because they have this structure:
\[/LM/W3SVC/<Web site number> /Root /<virtual directory name>\]
On my demonstration server, for example, I have \[/LM/W3SVC/1/Root/Certsrv\] and \[/LM/W3SVC/1/Root/Demos\]. Carefully copy the definitions in the directory listing sequence you desire. Make sure you have only one blank line between each listing.
After you complete the reorganization, save the text file. Although nothing we've done so far has placed the metabase itself at risk of being changed, that all ends here.
At this point, stop all Web services. In IIS 5.0, you use the IISRESET /STOP command. In IIS 4.0, you stop the IIS Admin Service by using NET STOP IISADMIN. Close MetaEdit, then open the Internet Services Manager console and locate the Web site you want to reorganize. Delete the Web site's virtual directories, then close the console.
Open MetaEdit and import the modified text file. Close MetaEdit, then open the Internet Services Manager console again. Your virtual directories are now in the sequence you specified. Restart the Web server.
Despite the work required to gain the benefit, if your IIS directory structure is relatively stable and you reference it frequently, the effort might be worth it. A couple of quick caveats about this technique: I don't like to have both the Internet Services Manager console and MetaEdit open at the same time. Because both update the same data store, you don't want older information from one of the applications to update the metabase while you're editing in the other application. Note that if you use MetaEdit 2.1 (which is included in the Microsoft Windows 2000 Resource Kit), editing the metabase with both tools open can cause the server to be unstable (i.e., blue screen). You should use MetaEdit 2.2, which you can download at http://downloadmicrosoft.com/download/iis50/utility/5.0/nt45/en-us/mtaedt22.exe.