Working with Special Folders

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

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

IdentifierFolder Contents
AllUsersDesktopShortcuts that appear on the desktop for all users
AllUsersStartMenuShortcuts that appear on the Start menu for all users
AllUsersProgramsShortcuts that appear on the Programs menu for all users
AllUsersStartupShortcuts to programs that are run on startup for all users
DesktopShortcuts that appear on the desktop for the current user
FavoritesShortcuts saved as favorites by the current user
FontsFonts installed on the system
MyDocumentsCurrent user s documents
NetHoodObjects that appear in Network Neighborhood
PrintHoodPrinter links
RecentShortcuts to current user s recently opened documents
SendToShortcuts to applications that show up as possible send-to targets when a user right-clicks on a file in Windows Explorer
StartMenuShortcuts that appear in the current user s start menu
StartupShortcuts to applications that run automatically when the current user logs on to the system
TemplatesApplication 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 .htm files. If you right-click on a .htm file and click Edit, the file will open in FrontPage.

Of course, there might be times when you simply want to view the .htm 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 .htm 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

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net