Microsoft® Windows® 2000 Scripting Guide
« Previous | Next »
When you right-click a Shell object in Windows Explorer, a shortcut menu appears showing actions that can be performed on that object. For example, when you right-click a VBScript file, you see such options as Open, Edit, Print, Create Shortcut, and Delete.
Within the Shell nomenclature, each of the commands that appear on a shortcut menu is known as a verb. A verb is a text string in the registry that specifies the command to be run when the menu item is clicked. Different objects have a different set of verbs. The Recycle Bin, for example, does not have a Print option, but it does have an Empty Recycle Bin option.
The FolderItem object features an InvokeVerbEx method that allows you to execute any of the verbs associated with an object. For example, this command opens the associated file:
objFile.InvokeVerbEx(
"Open
")
Calling InvokeVerbEx without specifying a verb automatically invokes the default verb for the object. For example, with a Windows Media file, the default verb is Play; for a folder, the default verb is Open.
Be aware that verbs always function in exactly the same way they do when clicked in Windows Explorer. If you right-click a file and select Open, the file automatically opens. If you select Delete, however, a confirmation box is displayed before the file is deleted. This same confirmation box appears if you attempt to delete any object using InvokeVerbEx. For example, using the Delete verb on a file results in a dialog box similar to the one shown in Figure 11.8.
Figure 11.8 Confirmation Dialog Box
Confirmation Dialog Box
By comparison, right-clicking a file and selecting Print does not display a dialog box; instead, the file is automatically printed to the default printer. If you use InvokeVerbEx to print a file programmatically, that file is automatically printed to the default printer without displaying a dialog box of any kind.
Listing 11.27 contains a script that prints all the files in the folder C:\Logs. To carry out this task, the script must perform the following steps:
Listing 11.27 Performing Actions on Files
|
|
Send us your feedback | « Previous | Next » |