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

Identifier

Folder Contents

AllUsersDesktop

Shortcuts that appear on the desktop for all users

AllUsersStartMenu

Shortcuts that appear on the Start menu for all users

AllUsersPrograms

Shortcuts that appear on the Programs menu for all users

AllUsersStartup

Shortcuts to programs that are run on startup for all users

Desktop

Shortcuts that appear on the desktop for the current user

Favorites

Shortcuts saved as favorites by the current user

Fonts

Fonts installed on the system

MyDocuments

Current users documents

NetHood

Objects that appear in Network Neighborhood

PrintHood

Printer links

Recent

Shortcuts to current users recently opened documents

SendTo

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

StartMenu

Shortcuts that appear in the current users start menu

Startup

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

Templates

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.

Note

  • 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

  
1
2
3


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

  
1
2
3
4
5
6
7
8
9


Set objShell = WScript.CreateObject("WScript.Shell")
strSendToFolder = objShell.SpecialFolders("SendTo")
strPathToNotepad = objShell.ExpandEnvironmentStrings _
 ("%SystemRoot%/system32/notepad.exe")
 
Set objShortcut = objShell.CreateShortcut(strSendToFolder & _
 "\notepad.lnk")
objShortcut.TargetPath = strPathToNotepad
objShortcut.Save

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