Managing Files and Folders Using the Windows Shell Object

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

The Windows operating system features another COM object, the Shell object, that includes a number of properties and methods useful in managing file systems. Because the Shell object offers capabilities not available using either the FileSystemObject or WMI, you should also consider it when writing scripts for file system management.

The Shell is the portion of the Windows operating system tasked with managing and providing access to such things as:

  • Files and folders
  • Network printers
  • Other networked computers
  • Control Panel applications
  • The Recycle Bin

The Shell namespace provides a way to manage these objects in a tree-structured hierarchy. At the top of this hierarchy is the Desktop; directly below the Desktop are virtual folders such as My Computer, My Network Places, and Recycle Bin. Within each of these virtual folders are other items (such as files, folders, and printers) that can also be managed using the Shell. If you start Windows Explorer, you see a visual representation of the Shell, as shown in Figure 11.1.

Figure 11.1   The Shell Namespace

The Shell Namespace

The Shell itself is composed largely of a series of COM objects, many of which can be accessed using VBScript. Included among these COM objects are folders. Within the Windows operating system, folders are individual COM objects that possess:

  • Properties, such as a size and a creation date.
  • Items (typically files stored within the folder).
  • Methods (known as verbs), which represent actions such as Copy and Delete that can be carried out on the folder.

Folder objects and all the properties, items, and methods belonging to those objects can be accessed through the Shell object. The Shell object provides a way to programmatically reproduce all the features found in the Windows Shell. This means that file system management tasks which typically involve working with files and folders can be carried out using the Shell object.

Scripting the Shell object is not as intuitive as scripting with WMI or the FileSystemObject. For example, to bind to a file using a Shell object script, you must:

  1. Create an instance of the Shell object.
  2. Create an instance of a Folder object.
  3. Create a collection of items in the folder.
  4. Iterate through the collection until you find the desired file.

This is considerably more complicated than using the FileSystemObject or WMI. On the other hand, the Shell object does offer a number of capabilities not found in either WMI or the FileSystemObject, including the ability to:

  • Retrieve extended properties for a file or folder (for example, the artist, album title, and track number for an audio file).
  • Display a progress dialog box while copying or moving folders.
  • Retrieve the locations of all the special folders on a computer.
  • Carry out any of the commands found on the shortcut menu when you right-click a file or folder.

In this chapter, the Shell object is used whenever it provides a unique capability not available using either WMI or the FileSystemObject.


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