Hack22.Control Windows Explorer with Command-Line Shortcuts


Hack 22. Control Windows Explorer with Command-Line Shortcuts

Create customized Explorer views from the command line, and save your favorite views in desktop shortcuts.

I rarely open Windows Explorer in its default view. Instead, I generally want to open it at a specific location, with a specific set of viewing featuresfor example, with the Folders bar in the left side on or off.

I launch Windows Explorer from the command line, along with a set of switches for controlling how it opens. I also create desktop shortcuts out of these command-line launches so that my favorite views are always only a couple of clicks away.

For example, when I want to open Windows Explorer to the C:\Power Tools Book\Hacks subfolder only, with no folders above it, and using the Folders bar, I open the command prompt and issue this command:

explorer /e,/root,c:\Power Tools Book\Hacks

When I do that, the view pictured in Figure 3-7 appears.

Figure 3-7. Opening Windows Explorer to a specific folder with a specific view


Compare that view with my default view that I get when I launch Windows Explorer the normal way (shown in Figure 3-8).

Figure 3-8. My default for launching Windows Explorer


Not only does the Explorer view in Figure 3-7 open to a specific subfolder, but it also shows no folders above it. In contrast, Figure 3-8 shows the entire structure of my hard disk and opens to C:\. I use the view in Figure 3-7 when I want to work exclusively on a specific subfolder and want to get to it quickly.

This is just one of the many uses for launching Windows Explorer from the command line with switches; no doubt you'll be able to find other uses for it. You'll be able to use it not only on the command line and with desktop shortcuts, but also if you run scripts and batch programs.

The syntax for running Explorer from the command line with switches is:

explorer  [/n]  [/e] [,root,object] [[,/select],subobject]

You don't have to use switches; you can type explorer by itself, though doing that launches your default Explorer view.

Here is an explanation of how to use the switches and syntax:


/n

Opens Windows Explorer without displaying the Folders bar, the tree structure of the hard drive. Instead, it launches the view shown in Figure 3-9.

Figure 3-9. The view of Explorer using the /n switch



/e

Opens Windows Explorer displaying the Folders bar.


/root,object

Opens Windows Explorer to a specific object, such as a folder, without displaying the folders above it, as shown in Figure 3-7. You can also use Globally Unique Identifiers with this switch, as explained later in this hack.


[[/select],subobject]

Opens Windows Explorer to a specific file or folder that is then highlighted or expanded. You can use the subobject switch only without the /select parameter. When you include the /select parameter, the branches are not expanded, the folder is highlighted, and the subobject is highlighted in the right pane.

3.3.1. Create Desktop Shortcuts for Explorer

Typing command-line shortcuts can quickly give you a case of carpal tunnel syndrome, so a better idea is to run them as desktop shortcuts. Right-click the desktop, choose New Shortcut, and in the location box type the Explorer command-line syntax you want to use. Click Next and give the shortcut a descriptive namefor example, "Hacks folder"and click OK.

3.3.2. Using Globally Unique Identifiers with Command-Line Switches

You might want to open Explorer to certain system foldersfor example, to My Network Places. To do so, run explorer from the command line and follow it with a space, two colons, and the Globally Unique Identifiers (GUIDs) that identify specific system folders, like this:

explorer  ::{208D2C60-3AEA-1069-A2D7-08002B30309D}

That command opens Windows Explorer to My Network Places.

If you're using switches, similarly put a space and two colons in front of the GUID, like this:

explorer /e, ::{208D2C60-3AEA-1069-A2D7-08002B30309D}

You can use GUIDs in desktop shortcuts, batch files, and scripts, as well as at the command line. Table 3-1 lists the GUIDs for various system folders.

Table 3-1. GUIDs for system folders

Folder name

GUID

My Computer

{20D04FE0-3AEA-1069-A2D8-08002B30309D}

My Network Places

{208D2C60-3AEA-1069-A2D7-08002B30309D}

Network Connections

{7007ACC7-3202-11D1-AAD2-00805FC1270E}

Printers and Faxes

{2227A280-3AEA-1069-A2DE-08002B30309D}

Recycle Bin

{645FF040-5081-101B-9F08-00AA002F954E}

Scheduled Tasks

{D6277990-4C6A-11CF-8D87-00AA0060F5BF}




    Windows XP Hacks
    Windows XP Hacks, Second Edition
    ISBN: 0596009186
    EAN: 2147483647
    Year: 2003
    Pages: 191

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