Guy's Scripting Ezine 119 - ShortcutsGuy's Scripting Ezine 119 - VBScript Desktop Shortcuts
♣ This Week's SecretIf the car was the only form of transport that you knew about, then you would miss out flying in a plane or sailing in ship. So it is with scripting, if you only knew about network objects then you are denying your self a whole area of scripting, for example shell objects. So that I can troubleshoot scripts, I like to increase my range of CreateObject("WScript.NOUNS"). Take the case, where I cannot get the correct method to work, for example obj.CreateShortcut or obj.SendKeys. The underlying problem is that before I can use .createShortCut, I must create a shell object and not a network object. Consequently, this is what I would script: CreateObject("WScript.Shell"). CreateShortcut and indeed SendKeys, are methods available for shell objects, but are not available if you create network objects. This Week's MissionThis week's mission is to create a desktop shortcut. You may wish to do this if you have a proprietary program that you are rolling out to a group of users. The idea is to provide a desktop shortcut via a logon script. What happens is users double click on the shortcut and thus execute their program, which may even be on a remote network share. If you are looking for handy network utilities, try some of the free downloads at Tools4Ever Example Script: Create a desktop shortcutPre-Requisites None. However, after one or two test runs you may wish to change the variables in order to experiment with other descriptions, icons, or programs. Instructions
' CreateShortCut.vbs - Create a Desktop Shortcut. Learning PointsNote 1: Observe how we create a shell object with Set objShell = CreateObject("WScript.Shell") Note 2: Once we have created the shell object then we can manipulate it with methods, for example .CreateShortCut Note 3: On its own, the shortcut link is not much use; we need to give it power by adding properties, the most important of which is .TargetPath. Note 4: Trace how the variables control the objLink properties. Employing variables makes it easier to amend the script and thus create shortcuts which launch different applications. Note 5: See how the script takes care of the path with: objDesktop = objShell.SpecialFolders("Desktop") VBScript Desktop Shortcut Challenges1) Amend the icon. This is just a cosmetic change in the appearance of the desktop icon. Try replacing 5 with 175 in: strIconPath = "%SystemRoot%\system32\SHELL32.dll,175". To research the available icons, right click the icon, select properties, Change Icon and make your choice. It seems to me that the logic was the first icon is zero, then you count down (row-wise), thus the bottom of the first column is 3, top of the second column 4 and so on. 2) Research your own applications. If you cannot think of any try WordPad, Paint or even Freecell. Once you have found another executable, amend the strAppPath. 3) Create a Windows 8 Metro UI Tile Guy Recommends:
The Free IP Address Tracker (IPAT)
|
|||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |