Recipe 4.6. Customizing the Way Applications Open Using Switches and Parameters


Problem

You want to customize the way you open an application. For example, you might want Microsoft Word to run a specific macro when it first starts.

Solution

Using a graphical user interface

When you use a shortcut to launch a program, as outlined in Recipe Recipe 4.5, you can use parameters and switches that let you customize the way it runs. These switches and parameters are usually specific to each individual program, although some work on many or all programs.

For example, you can launch any Microsoft Office application and have it automatically open a specific document by using the right syntax in the Target box. For example, if you wanted to launch Microsoft Word and have it automatically open a file called Chapter 9.doc in the C:\Power Tools Book directory, you'd put this in the Target box (make sure to include the quotes):

"C:\Program Files\Microsoft Office\Office11\WINWORD.EXE" "c:\Power  Tools Book\Chapter 9.doc"

In addition to launching individual files, you can use a variety of switches. For example, if you wanted to open Word without opening a document and not have previously opened documents show up in the Word File menu, you'd use the switch /n in the Target box:

"C:\Program Files\Microsoft Office\Office10\WINWORD.EXE" /n

And you can combine switches with opening individual files. So if you wanted to run Word and have it open a file called Chapter 9.doc in the C:\Power Tools Book directory, and have Word run a specific macro but not run any Autoexec macros, you'd use this syntax:

"C:\Program Files\Microsoft Office\Office11\WINWORD.EXE" /m "c:\Power  Tools Book\Chapter 9.doc"

Tables 4-2 through 4-5 list switches for Microsoft applications Word, Excel, PowerPoint and Outlook.

Table 4-2. Switches for starting Word

Switch

What it does

/a

Stops add-ins and global templates, including the Normal template, from being loaded automatically. It also locks Word settings so that they cannot be read or modified.

/l addinpath

Loads a specific Word add-in.

/m

Starts a new instance of Word without running AutoExec macros.

/m filen

Opens the file specified by number on the File menu's Most Recently Used list.

/m macroname

Runs a specific macro and prevents Word from running any AutoExec macros.

/n

Starts a new instance of Word without opening a document. Documents opened will not appear as choices in the Window menu of other Word instances.

/t templatename

Starts Word with a new document based on the specified template.

/w

Starts a new instance of Word with a blank document. Documents opened will not appear as choices in the Window menu of other Word instances.

/r

Opens Word, reregisters it in the Registry, and quits. Use this switch if there have been problems with Word's settings and you want to reregister it.

/q

Starts Word without the splash screen.


Table 4-3. Switches for starting Excel

Switch

What it does

/r workbook path/filename

Opens the specified workbook as read-only.

/e

Opens Excel without a startup screen and without a new blank workbook.

/m

Opens Excel with a new workbook that contains a single macro sheet.

/p workbook path

Opens Excel and uses the specified path as the active path instead of the default path.

/o

Opens Excel and then reregisters it in the Registry. Use this switch if there have been problems with Excel's settings and you want to reregister it.

/regserver

Opens Excel, reregisters it, and quits.

/unregserver

Opens Excel, unregisters it, and quits.


Table 4-4. Startup switches for PowerPoint

Switch

What it does

/s

Opens a presentation into the slide show window.

/p

Prints the presentation.

/n template_name.pot

Creates a new presentation based on the specified template.


Table 4-5. Startup switches for Outlook

Switch

What it does

/safe:1

Starts Outlook with the Reading Pane off. (Only works with Outlook 2003.)

/safe:2

Starts Outlook without checking mail at start. (Only works with Outlook 2003.)

/select foldername

Opens the specified folder in a new window when Outlook starts.

/autorun macroname

Opens Outlook and runs the macro specified in macroname.


Using a command-line interface

You can use the same syntax, switches, and parameters at the command line as you can in the Target box when you create a shortcut. So you can launch applications using those parameters and switches straight from the command line.

When you use the command line to launch programs, make sure you get to the command line by typing cmd.exe at the Run box, not command.exe. The command.exe command line doesn't support long folder names.


To launch a program at the command line, type in its full path and filename, then press Enter, like this. (Note that you won't have to type in the path, if the file can be found in your PATH.)

C:\Program Files\Microsoft Office\Office11\WINWORD.EXE

Add switches and parameters as outlined earlier in this recipe. For example:

C:\Program Files\Microsoft Office\Office11\WINWORD.EXE /n

Discussion

The true power of using switches and parameters for launching programs comes into play when you use them with shortcuts. If you have a particular customized way that you generally like to launch an application, create a shortcut for it with the right switches and parameter, and normally run it that way. But then, when you vary from your normal way of launching it if you want to launch a specific file, for example it'll be easier to use the command line.

Also, consider creating multiple shortcuts for each of your applications, so that you can launch different customized versions.

Remember when you use the command line that the command you type in doesn't include quotes around it, but when you use the Target box for creating shortcuts, you need to include the quotes. (On the command line, though, if you're using a path with any spaces, you need to include quotes.) Finally, keep in mind that many applications, not just Microsoft Office applications, include switches and parameters you can use to launch them, so check your documentation or the web site of the software make to find them.

See Also

Recipe 4.5 for help in creating keyboard shortcuts; MS KB 130510, "Command-Line Switches for Windows Explorer," and MS KB 296192, "OL2002: Additional Command-Line Switches"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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