VBScripting Solutions: Customizing Folder Icons and Descriptions


When I was buying my first PC many years ago, a friend suggested that I create a few partitions on my new machine's hard disk to minimize the length of the directory listing. At that time, Microsoft had yet to invent Windows Explorer, so people typically used the MS-DOS Dir command to explore a disk's contents. My friend's advice made sense: When you need to quickly locate a certain folder, a short directory listing simplifies the task.

Now, Windows Explorer has scroll bars and multicolumn views to help users find folders. However, finding folders can still be difficult because hard disk capacity has grown so large and, by default, Windows Explorer uses the same yellow-folder icon for all folders. Fortunately, in Windows Explorer, you can make certain folders stand out from the crowd by customizing their icons and descriptions.

Folders in Windows Explorer
In Windows Explorer, a folder is more than a file-system directory. Just as a file-system directory is a container of files and subdirectories, a folder is a container of folder items and subfolders.

In most cases, a folder item maps to a file and a subfolder maps to a subdirectory. However, this mapping isn't a strict rule because file-system directories are only one type of folder that you can view and access through Windows Explorer. For example, you can also view and access the My Network Places and Printers folders, two special types of folders that contain unusual items—network connections and printers, respectively.

A system-provided module called the namespace extension renders each type of Windows folder. This COM component uses a suite of COM interfaces to communicate with Windows Explorer. The Windows OS installs this module and makes it visible to Windows Explorer through the registry. When Windows Explorer detects the presence of a new namespace extension, Windows Explorer interrogates the module by using the methods that the module's COM interfaces define.

To make a folder stand out, you could use the C++ language to write a custom namespace extension that creates a unique type of folder. However, even experienced programmers find this task complex. If you have Active Desktop installed on your Windows OS, you have a much easier alternative. To make a folder stand out, you can customize that folder's icon and description by creating or adapting a desktop.ini file.

Active Desktop and the Desktop.ini File
Active Desktop gives Windows OSs the ability to support HTML templates for folder views. In other words, you can use Active Desktop to render an HTML page that displays a folder's contents in the right pane of Windows Explorer. Active Desktop is part of Windows XP, Windows 2000, and Windows 98. If you have Windows NT 4.0 or Win95, you can download the Windows Desktop Update, which includes Active Desktop. For information about downloading and installing the Windows Desktop Update, see the Microsoft articles "How to Add or Remove Windows Desktop Update" (http://support.microsoft.com/directory/article.asp?id=kb;en-us;q165695) and "How to Install the Windows Desktop Update with Internet Explorer 5.x" (http://support.microsoft.com/directory/article.asp?id=kb;en-us;q254919).

To customize a folder's icon and description, you need to use HTML pages for folder views. The option to display Web content for folder views is automatically enabled in some OSs (e.g., XP, Win2K) but not others (e.g., NT 4.0). You can enable this feature from the General tab of the Folder Options dialog box. Figure 1 shows this dialog box in Win2K. To obtain this dialog box, select Folder Options from the Tools menu in Windows Explorer. In the Web View panel, select Enable Web content in folders. If you have other OSs, the options might differ. For example, in Win98, the General tab has the options Web style, Classic style, and Custom, based on settings you choose.

Each folder has a special entry in the internal file-system table. Each entry contains folder-specific information, such as the folder's name and attributes. When Microsoft initially designed the file-system platform, features such as folder icons and folder descriptions didn't exist. Thus, the internal file-system table doesn't have enough space to store all of today's needed directory information. For this reason, folders can contain a desktop.ini file, which plays the role of a simplified folder extension. A desktop.ini file applies only to the folder in which it resides. Depending on your shell settings, desktop.ini files might not be visible. To view all desktop.ini files, you can enable the Show hidden files and folders option on the View tab of the Folder Options dialog box, which Figure 2 shows.

When Windows Explorer recognizes desktop.ini as a system file, Windows Explorer uses the file's content to embellish and customize the look of the folder in which the file resides. Otherwise, Windows Explorer treats desktop.ini as an ordinary folder item. How do you mark a desktop.ini file so that Windows Explorer perceives it as a system file? The required configuration differs between XP and earlier Windows OSs. In XP, you open the desktop.ini file's Properties dialog box and select the System check box in the Attributes panel. In OSs earlier than XP, you open the Properties dialog box of the folder that contains the desktop.ini file and select the Read-only check box in the Attributes panel. Marking a folder as read-only doesn't affect the read/write activity of the folder or its contents. In a read-only folder, you can still create, delete, or modify subfolders and read/write files.

Configuring the Desktop.ini File
Like other Windows .ini files, a desktop.ini file consists of sections and entries. Every desktop.ini file has at least one section, and each section can have any number of entries (including no entries). A name enclosed in brackets identifies each section. Each entry under the section name is a name=value pair.

Figure 3 shows a sample desktop.ini file. This file has one section, .ShellClassInfo, which has three entries: Infotip, IconFile, and IconIndex. The Infotip entry contains the text that Windows Explorer will display when the cursor hovers over that folder's icon. Windows Explorer also writes this text in the folder view in the right pane, as Figure 4 shows. The Infotip text must be plain text and shouldn't contain any HTML tags. Although you won't get an error if the text includes HTML tags, Windows Explorer will display the tags as plain text.

The IconFile and IconIndex entries identify the icon that Windows Explorer is to use for that folder. The IconFile entry points to the file that contains the icon you want to display. You can specify any type of file (e.g., .ico, .exe, .dll), as long as the file contains icons. The IconFile value can be a Universal Naming Convention (UNC) path or local filename. The IconIndex entry points to the location of the icon in the specified file. Typically, you use a 0-based index number to specify the icon's ordinal position. You must specify an IconIndex value even if the file contains only one icon. When a file contains just one icon, you set IconIndex to 0. If you specify an invalid icon number, Windows Explorer doesn't display any icon.

When an icon file is a Windows executable, you can use an alternative approach to identify which icon to use. Each icon in a Windows .exe or .dll file has a unique ID number that identifies the icon as a resource of the application. You can use this resource ID number to specify the location of the icon in the file. However, you need to use a special notation to let Windows Explorer know that you're specifying the icon's resource ID number rather than the icon's ordinal position. To use the special notation, multiply the resource ID number by -1. So, for example, if the icon you want to use in the myicons.dll file has the resource ID number 235, you would use the following IconFile and IconIndex entries:


However, the icon's resource ID number might be hard for some systems administrators to obtain. The resource ID number is embedded in the resource file of the executable that contains the icon. You can discover resource ID numbers only with tools that can work with the resource files of Win32 applications (e.g., Microsoft Visual Studio—VS).

Customizing the icon and customizing the description aren't mutually dependent or exclusive. You can choose to customize an icon, customize a description, or both.

Putting It All Together
Now that you know the basics, let's look at how you can use this information. Suppose you want to manually customize the icon and description of a folder in Win2K's Windows Explorer. You would simply follow these steps:

  1. In the target folder, create a desktop.ini file that sets the Infotip, IconFile, and IconIndex entries in the .ShellClassInfo section.
  2. Enable the target folder's read-only attribute.
  3. Refresh Windows Explorer.

You follow these same steps when you want to programmatically customize a Win2K folder icon and description. The script CustomizeFolder.vbs, which Listing 1, page 4, shows, demonstrates how to automate these steps. When launching CustomizeFolder.vbs, you provide as many as four arguments:

  • A string that contains the name of the folder in which to create the desktop.ini file. This name can be a UNC path or local filename. The script assigns this argument to the folderName variable.
  • A string that specifies the name of the file containing the icon you want to display. This name can be a UNC path or local filename. The script assigns this argument to the iconFile variable.
  • The icon's index number or resource ID number. The script assigns this argument to the iconIndex variable.
  • A string that contains the folder's description. The script assigns this argument to the infoTip variable.

The only mandatory argument is the target folder's name. If you don't provide one of the optional arguments, the script assigns a default value to the respective variable, as the code at callout A in Listing 1 shows. With the variable values set, the script proceeds to create a desktop.ini file in the target folder, enable that folder's read-only attribute, and prompt the user to refresh Windows Explorer, as the code at callout B shows.

If the target folder already contains a desktop.ini file, you can adapt CustomizeFolder.vbs so that it opens (rather than creates) this file and adds the .ShellClassInfo section. To adapt the script, replace the line

Set f = fso.CreateTextFile _
(folderName & "desktop.ini")


Set f = fso.OpenTextFile _
(folderName & "desktop.ini")

With the desktop.ini file open, the script can append the .ShellClassInfo section to the end of the file. (In Windows .ini files, a section's ordinal position isn't important.)

CustomizeFolder.vbs doesn't work on XP machines. As I explained earlier, in XP, you check the desktop.ini file's System check box rather than the folder's Read-only check box to mark desktop.ini as a system file. Although you can't use this script, you can use XP's system-provided dialog box to interactively customize a folder's icon and description.

A Reprieve from the Same Yellow Folders
Quickly locating a particular folder among a flood of yellow folders can be difficult. Creating or adapting a folder's desktop.ini file gives you a way to customize that folder's icon and description, saving you time and frustration when you need to find the folder.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.