Downloads
9176.zip

The Windows 2000 user interface (UI) might appear to be a revolutionary change if you've never installed the Shell Update Release (SUR). Microsoft originally made SUR available as a separate add-on to Microsoft Internet Explorer (IE) 4.0. (For information about installing SUR, see the Web-exclusive sidebar "Installing the SUR Add-On" on the Win32 Scripting Journal Web site at http://www.win32 scripting.com/.) Microsoft designed SUR with the notion that browsing the local file system is just a special case of browsing the Web. Microsoft continued to follow this notion when it designed the shell of the Win2K OS and, to some extent, the shell of the Windows 98 OS. However, Microsoft began calling SUR a new name: Active Desktop. (Microsoft also calls SUR the Desktop Update in some documentation.)

Active Desktop presents a folder's content (i.e., subfolders and files) as a component embedded in an HTML page. Thus, the folder takes up only a limited amount of space when you display its contents in Windows Explorer's right pane. Perhaps more important, Active Desktop lets you provide additional controls and information in Windows Explorer's right pane.

For example, Figure 1 shows the contents of the folder My Computer. Active Desktop renders the folder's contents through an HTML page that contains the component (an ActiveX control) displaying the folder's files and subdirectories. The HTML page also includes three additional buttons (New, DOS, and Select) and a text box. Any component that you can insert in an HTML page (e.g., links, tables, images, controls), you can insert in Windows Explorer's right pane. You can customize the look and functionality of any folder by adding new components to the HTML template that Windows Explorer uses to render that folder. Furthermore, you can use scripts to make these new elements interact.

You can apply such customization on a per-folder basis or a global basis (i.e., all folders in the system). If you want a certain folder to implement a special functionality, you associate a local HTML template to that folder. If you want to make all folders implement a special functionality, you change the standard system-provided HTML template called folder.htt. Win2K uses this HTML template for all folders except those in which you specify a customized template.

Although Win2K enables Web content in folders by default, you can disable this feature if you don't want Web content in Windows Explorer's right pane. In Windows Explorer, select Folder Options from the Tools drop-down menu and click the General tab in the Folder Options dialog box. Under Web View, select the Use Windows classic folders option, as Figure 2 shows. The classic style view is the view that Windows NT 4.0 uses to display folders' contents.

If you enable Web content, Active Desktop offers many Web- and HTML-related features that you can take advantage of. These features let you customize many parts of the Win2K UI, including infotips (i.e., text that provides information at the shell level), the Quick Launch toolbar, folders' icons, and folders' contents.

Customizing Infotips
In Win2K, you can make your system show customized information about a shortcut or file when your cursor hovers over that shortcut or file. Although complete control of infotips is possible only by writing a C++ COM object, you can gain some control of shortcut and file infotips by writing Windows Script Host (WSH) code.

Shortcut infotips. Creating shortcut infotips is simple. Take, for example, the myshortcut shortcut and infotip in Figure 3. Listing 1 contains the code that creates this shortcut and infotip. In this code, you create an instance of the WshShell object, then use that object's CreateShortcut method to create an instance of the WshShortcut object. After you set the WshShortcut object's TargetPath property to specify where the shortcut points (in this case, the root of drive C), you set the object's Description property to the infotip text (in this case, the text This shortcut points to C:\). Finally, you save the shortcut with the WshShortcut object's Save method. After you run this code, Win2K will automatically display the infotip whenever you hover your cursor over the myshortcut icon.

File infotips. Win2K provides a standard infotip for all types of files unless you provide customized text. By default, Win2K forms the file infotip's text by concatenating the information about the file's type (i.e., the information in Windows Explorer's Type column), author, title, subject, comment, and size. All files have type and size information, but not all files have an author, title, or comment. When the shell is about to display the infotip for a file, it gathers all the information available and prepares a string. (The shell doesn't display blanks if information is missing.)

Two ways exist to customize file infotips. One approach is to write a C++ COM object that implements the IQueryInfo COM interface. However, this approach requires you to be familiar with C++ and COM development, so it isn't practical for most scriptwriters. A more practical approach is to enter a short string in the appropriate Registry key with code such as that in Listing 2. In this code, you create an instance of the WshShell object, then use that object's RegRead method to return the appropriate Registry key (in this case, HKEY_ CLASSES_ROOT\.asp\). You then use the WshShell object's RegWrite method to set a new value for that key. If you run the code in Listing 2, any Active Server Pages (ASP) file will have an infotip that reads This is an ASP page.

Customizing the Quick Launch Toolbar
You can use WSH code to programmatically add shortcuts to the Quick Launch toolbar. All the items in the Quick Launch toolbar are based on shortcuts in the System folder called Application Data. The path to this folder is user and location specific. For example, if you're logged on as the administrator for the English version of Win2K, the path is C:\Documents and Settings\Administrator\Application Data. In this folder, the \Microsoft\Internet Explorer\Quick Launch subtree stores the shortcuts for the Quick Launch toolbar. So, to add an item to the toolbar, you need to add a shortcut to the Quick Launch folder.

For example, suppose you want to add Notepad to the Quick Launch toolbar. You can use the code in Listing 3 to add a Notepad shortcut to the Quick Launch folder. You begin this code by creating an instance of the WshShell object. This object's SpecialFolders property retrieves the Windows shell folder you specify. In this case, you want the path to the Application Data folder, so you specify AppData as the argument. You then concatenate the path that the SpecialFolders property returns to the sub-tree path \Microsoft\InternetExplorer\ Quick Launch. Next, you use the WshShell object's CreateShortcut method to create an instance of the WshShortcut object. You set the WshShortcut object's TargetPath and Description properties to create the shortcut and its infotip, respectively. Finally, you save the changes you made.

Customizing Folders' Icons
To locate folders quickly in Windows Explorer, you can assign any folder a custom icon and description. Assigning a custom icon and description involves two steps:

  1. Enable the folder's read-only attribute. You can enable the attribute programmatically or through the folder's Properties dialog box. When you enable this attribute, Windows Explorer treats the .ini file you create in step 2 as a special content file.
  2. Create a system text file called desktop.ini in the folder. You can use Notepad to create this file, which contains lines similar to those in Figure 4. The IconFile entry points to the file containing the icon you want to display. This file can be an .ico file or an executable module (e.g., .exe, .dll, .drv, .ocx) that includes icons within its resources. If you use an icon from an .ico file, set the IconIndex entry to the 0-based ordinal position of the icon you want (e.g., 0 represents the first icon, 1 represents the second icon). If you choose an icon from an executable module, set IconIndex to either the 0-based ordinal position of the icon or to the icon's ID number. The person who writes the module assigns the icon ID numbers, so you need to read the module's documentation to obtain them. When you specify the icon ID number, add a minus sign (-) in front of it. The minus sign tells the shell to load the icon using the ID number's absolute value.

Customizing Folders' Contents
To customize folders' contents in Windows Explorer's right pane, you right-click in the folder area (but not in the space reserved for files) and select Customize This Folder from the menu. The Customize This Folder Wizard lets you change the folder's HTML template to completely alter the appearance of the folder and its files, change the background image for the files, or change a comment about the folder. If you choose to change the HTML template, the wizard prompts you with the standard HTML template (i.e., folder.htt). You can use Notepad to change the template's source code. The code's comments can help you identify which lines to change.

For example, suppose you want to add a link to the Win32 Scripting Journal Web site to the standard HTML template. First, you locate line

Info.innerHTML = text;

within the body of the ShowInfo() JavaScript function. Then, you replace this line with the code in Listing 4.

You can edit the standard HTML template at any time. The folder.htt file is in the Folder Settings folder. By default, this folder is hidden, so to see it, you must enable this setting under the Hidden Files and Folders option on the View tab in the Folder Options dialog box.

After the Customize This Folder Wizard finishes customizing a folder, that folder contains a desktop.ini file with lines like those in Figure 5. You can modify the PersistMoniker entry so that it points to a custom HTML template. For example, if you write a custom HTML template called users .htt, you can change the highlighted line in Figure 5 to

PersistMoniker=file://users.htt

An HTML template is basically an HTML page. Aside from the file extension, the only difference between an HTML template and an HTML page is that, when the Win2K browser (IE 5.0) processes an HTML template, IE 5.0 automatically recognizes three environment variables: %THISDIRPATH%, %THISDIRNAME%, and %TEMPLATEDIR%. IE 5.0 expands these three variables into the current folder's fully qualified path name, the current folder's name, and the system path that points to the standard HTML templates, respectively. For example, to display the name of the current folder in the HTML template, you specify

This folder is <b>"%THISDIRNAME%"</b>

When writing a custom HTML template, you need to consider two points. First, whenever possible, write self-contained files. An HTML page can refer to external files to import script code and cascading style sheet (CSS) definitions. In an HTML template, however, I recommend that you insert as much of the script code and CSS definitions as possible into the .htt file because the template will be more efficient, especially if you want to share the customized folder over a LAN. Because you can't embed images or ActiveX controls in an .htt file, I recommend minimizing their use to speed the rendering of the folder's content.

Second, an HTML template completely hides the folder's standard content. As a result, unless you take a countermeasure, the only way you can look at the folder's content is to disable the Web View option for all folders. Thus, I recommend that you insert a back door in the template that lets users switch between the custom and standard views.

For an example of how to build a custom HTML template for a folder, see the Web-exclusive sidebar "Building a Custom View for a Folder" on the Win32 Scripting Journal Web site. This template includes a back door for switching views.

Build an Effective UI
Active Desktop contains many handy features that let you customize the Win2K UI. An effective UI can help users and systems administrators perform their jobs more easily and find information more quickly. Customizing the Active Desktop isn't for everyone, but if you feel comfortable with making such customizations, you can build a UI that can benefit your users and systems administrators.