Export (0) Print
Expand All

Working with Special Folders

Microsoft® Windows® 2000 Scripting Guide

Special folders are folders that are or at least potentially can be present on all Windows computers; these include the My Documents, Fonts, and Start Menu folders. There are two types of special folders: those that map to standard directories and those that do not. The Favorites folder, for example, maps to a standard directory; the My Computer folder does not.

The WScript SpecialFolders collection contains the full path to each of the special folders that map to a standard directory. Table 3.11 lists the identifiers and the contents of each of the special folders in the SpecialFolders collection.

Table 3.11 Special Folders Identifier


Folder Contents


Shortcuts that appear on the desktop for all users


Shortcuts that appear on the Start menu for all users


Shortcuts that appear on the Programs menu for all users


Shortcuts to programs that are run on startup for all users


Shortcuts that appear on the desktop for the current user


Shortcuts saved as favorites by the current user


Fonts installed on the system


Current users documents


Objects that appear in Network Neighborhood


Printer links


Shortcuts to current users recently opened documents


Shortcuts to applications that show up as possible send-to targets when a user right-clicks on a file in Windows Explorer


Shortcuts that appear in the current users start menu


Shortcuts to applications that run automatically when the current user logs on to the system


Application template files specific to the current user

To determine the location of any folder, retrieve the value of the SpecialFolders.Item property, specifying the name of one of the identifiers shown in Table 3.11.


  • The SpecialFolders collection enables your script to determine the path of any special folder that maps to a standard directory but does not enable your script to manipulate that folder or its contents. You must use a mechanism such as the FileSystemObject to actually work with the contents of the special folders. For more information about using the FileSystemObject in your scripts, see "Script Runtime Primer" in this book.

Retrieving the Location of Special Folders

The script in Listing 3.20 determines the location of the Fonts special folder. The script echoes the location of the Fonts folder.

Listing 3.20 Determining the Location of the Fonts Folder


Set objShell = WScript.CreateObject("WScript.Shell")
strFontDirectoryPath = objShell.SpecialFolders.Item("Fonts")
Wscript.Echo "Font Directory Path: " & strFontDirectoryPath

Creating a Shortcut in a Special Folder

When you install an application, that application often associates itself with a particular file type. For example, when you install the Microsoft® FrontPage® Web site creation and management tool, FrontPage associates itself with all .asp files. If you right-click on a .asp file and click Edit, the file will open in FrontPage.

Of course, there might be times when you simply want to view the .asp file in Notepad. Recognizing this fact, Windows includes a special folder named SendTo. The SendTo option presents a menu of applications or locations to which you can send the selected file. You can add to the options available in the SendTo menu by adding shortcuts to the SendTo special folder. The next time you want to open an .asp file (or any file) in Notepad, you can simply right-click the file, select SendTo, and then click Notepad.

The script in Listing 3.21 creates a shortcut to the Notepad application in the SendTo special folder, thus adding Notepad to the SendTo menu.

Listing 3.21 Adding the Notepad Application to the SendTo Menu


Set objShell = WScript.CreateObject("WScript.Shell")
strSendToFolder = objShell.SpecialFolders("SendTo")
strPathToNotepad = objShell.ExpandEnvironmentStrings _
Set objShortcut = objShell.CreateShortcut(strSendToFolder & _
objShortcut.TargetPath = strPathToNotepad

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft