Table of Contents |
The Shortcut ObjectShortcut objects are created by using the Shell object's CreateShortcut method. This method only specifies the final location for the shortcut; it doesn't allow you to specify the shortcut's own properties. To do that, you modify the properties of the Shortcut object, and then call the Shortcut object's Save method to save your changes. Methods and PropertiesThe Shortcut object offers the following properties.
You can create two types of shortcuts:
You'll see examples of both in Listing 11.2. Practical ApplicationListing 11.2 shows an example script that creates both a normal application shortcut and a URL shortcut. Listing 11.2. Shortcuts.vbs. Creates shortcuts on the user's desktop.' this sample creates two shortcuts on the current user's desktop ' shows how to use the Shell interface from within Script. 'first, we need to create an instance of the shell object dim objShell set objShell = WScript.CreateObject("WScript.Shell") 'next, we need to get the path to the special Desktop folder dim strDesktop strDesktop = objShell.SpecialFolders("Desktop") 'now, we can create shortcuts on the desktop 'let's do Internet Explorer dim objShortcut set objShortcut= objShell.CreateShortcut(strDesktop & "\IE.lnk") with objShortcut .TargetPath = "iexplore.exe" .WindowStyle = 1 .Hotkey = "CTRL+SHIFT+I" .Description = "Launch Internet Explorer" .WorkingDirectory = strDesktop .Save end with 'let's create a link to my home page dim objURL set objURL = objShell.CreateShortcut(strDesktop & _ "\BrainCore Website.url") objURL.TargetPath = "http://www.braincore.net" objURL.Save I briefly introduced you to the With…End With construct earlier. Here, it's used so that I don't have to keep retyping objShortcut over and over. Each of the lines following the With statement begins with a period, and so VBScript assumes I'm talking about objShortcut, the object mentioned in the With statement. |
Table of Contents |