The magazine of the Melbourne PC User Group

Visual Basic Script And Two Shortcut Wizards
Keith Phillips
 
Shortcuts can be made by Visual Basic Script (vbs), see Note1. VBS code can be executed by wscript.exe, see Note 2. These programs can be run using the methods described in PC Update, August, September and October 2001.

Create The "MAKE Shortcut" Wizard

In C:\CLU, use a text editor to create SCwiz.bat (Figure 1), SCwiz.vbs (Figure 2) and a data file, VBS-LIST (Figure 3). SCwiz.vbs is based on a Microsoft example, see Note 3. In
Start Menu|Run, type the Command Line:

Wscript.exe C:\CLU\SCwiz.vbs

Click [OK] to create the shortcut in the SendTo directory. Tidy up: press Enter to close the "Windows Script Host" message box. Delete
VBS-LIST.
 
Open the
C:\WINDOWS\SendTo" directory, right click "SC to SCwiz.bat" and rename it "MAKE Shortcut". Customise its properties (Figure 4 shows only the properties to be checked or altered, leave all other properties unchanged). See Note 4 and then use "Run Qbasic" in C:\CLU to create SCwiz.bas(Figure 5) and see Note 5.

Use The "MAKE Shortcut" Wizard

Make a shortcut named "
SC to EXPLORER.EXE" on the Desktop. Before making this shortcut, click any icon on the Desktop and then press S repeatedly to successively highlight file names beginning with S. If "SC to EXPLORER.EXE" already exists, it will be modified unless you rename it. 

Then:

  1. In Windows Explorer, open the C:\WINDOWS directory, right click EXPLORER.EXE and send it to "MAKE Shortcut". This makes three text fields: the Program Name, the Command Line and the Working Directory.  Press any key to close the Wizard.

  2. Right click the C:\WINDOWS\Desktop directory, send it to "MAKE Shortcut" and press 4 to make it the Location for the shortcut (Figure 6).

  3. Press Y to create the shortcut. Press Enter to close the message box. Press Enter to close the Wizard. Then a "My Computer" window opens and displays the files in the Location directory.
Notes:

Note 1: In PC Update, April 2001, p58, Rod Ream warned that Visual Basic Script (VBS) is used to create some viruses. A remedy is to modify the associated File Type for "Windows Script Files". Detailed instructions are given in the article. The remedy doesn't interfere with "MAKE Shortcut" because it doesn't use file association, it uses a Command Line.

Note 2: If Wscript.exe is not in your Windows directory, see if you can install it from your Windows CD-ROM. Open Start Menu |Settings |Control Panel |Add/Remove Programs |Windows Setup |Accessories |Details. Then scroll down to "Windows Scripting Host". If it is in the list, tick it and click [OK] [Apply] [OK]. This also installs example scripts in the C:\WINDOWS\SAMPLES\WSH directory. Also, search the Windows CD-ROM for wshadmin and copy wshadmin.hlp and wshadmin.cnt into the WSH directory with the samples. To read the help contents, double click wshadmin.hlp, or make a shortcut to it. The latest version of Wscript.exe can be downloaded from http://msdn.microsoft.com/downloads. Search for "Microsoft Windows Script", scroll down the results list and select the script for your version of Windows.

Note 3: The Microsoft script named "Shortcut.vbs" makes only ONE shortcut (to NOTEPAD) in only ONE directory (the Desktop). Microsoft allows the file to be modified and distributed provided the user agrees that Microsoft has no warranty, obligations or liability for any Sample Application Files. In SCwiz.vbs the script has been modified to read file names and paths from a data file so it can make a shortcut to ANY program and it can put the shortcut into ANY directory.

Note 4: The Qbasic help path was omitted in the 2001 programs. Open the C:\CLU directory and double click "RUN Qbasic". In Qbasic, open the Options Menu, click Help Path, type C:\QB and click [OK]. Press Shift+F1 for general help, or put the cursor on a Qbasic Command and press F1 for specific help. Press Esc to clear the help screen and return to Qbasic.

Note 5: The Command Line to run Explorer.exe in SCwiz.bas (lines 36 & 38), is different to the usual Windows Command Lines. Quote characters are not required for long folder names or names with spaces. The parameters /select, and /n, must have the comma followed by the space. The displayed names of shortcuts have extensions that you don't see because Windows Explorer hides them. The extension for shortcuts to Windows applications is .lnk and the extension for shortcuts to MS-DOS applications is .pif so the mask ".*" is added to the shortcut name in SCwiz.bas (line 36) to find both types of shortcut.
@echo off

dir %1 /a >C:\CLU\DIR-LIST

C:\QB\Qbasic.exe /RUN C:/CLU/SCwiz.bas

C:\CLU\SCwiz.bas

      

      Figure 1.  SCWix.bat   

 SCwiz.bat



 C:\CLU\SCwiz.bat

 C:\CLU

 C:\Windows\SendTo  



     Figure 3.  VBS-LIST

     

     

'*********** Read the data from VBS-LIST ***********

Set OBJ = CreateObject("Scripting.FileSystemObject")

Set FileData = OBJ.OpenTextFile("C:\CLU\VBS-LIST")

Text1 = FileData.ReadLine    'The Program to execute

Text2 = FileData.ReadLine     'Cmd line to path\file

Text3 = FileData.ReadLine     'The Working directory

Text4 = FileData.ReadLine     'Location for shortcut

FileData.Close                'Finished reading data

Dim WSHShell '***** Prepare to make a shortcut *****

Set WSHShell = WScript.CreateObject("WScript.Shell")

Dim Conjuring    'The object that makes the shortcut

'********** Make the name of the shortcut **********

'NOTE: Code ending with _ continues on the next line

Set Conjuring = WSHShell.CreateShortcut(Text4 _

& "\SC to " & Text1 & ".lnk")

'NOTE: All shortcuts will be named "SC to" filename

'******* Make the command line to be executed ******

Conjuring.TargetPath = _

WSHShell.ExpandEnvironmentStrings(Text2)

'****** Make the path to the working directory *****

Conjuring.WorkingDirectory = _

WSHShell.ExpandEnvironmentStrings(Text3)

'******** Activate and display the shortcut ********

Conjuring.WindowStyle = 4

'****** Save the shortcut in the Icon Location *****

Conjuring.IconLocation = _

WSHShell.ExpandEnvironmentStrings(Text4 & ", 0")

Conjuring.Save

'************** Display a message ******************

CrLf = Chr(13) & Chr(10)

WScript.Echo "SC to " & Text1 & CrLf _

& "   Is Now In The Directory" & CrLf & Text4

'***************************************************

                    Figure 2.  SCWiz.vbs   

     


Figure 4


Figure 6

The new "SC to EXPLORER.EXE" shortcut is highlighted. Rename it "Explore C" and edit its Properties (Figure 7 explains how to blank out its Working Directory). The shortcut to EXPLORER.EXE has a blank Working Directory because it works in all directories. Make another "SC to EXPLORER.EXE" shortcut, rename it "Explore C_CLU" and add parameters to the Command Line (Figure 7). Test both shortcuts.


Figure 7


Figure 8


Figure 9

Find Programs For The "MAKE Shortcut" Wizard

If you don't know where a program is, search for it. For example, search the C: drive for PAD to find both
NOTEPAD and WORDPAD. Check that C:\CLU doesn't have a file named "SC to NOTEPAD.EXE" or a file named "SC to WORDPAD.EXE". In the search results list, right click NOTEPAD.EXE and send it to the Wizard to make three text fields (Figure 8). In Windows Explorer, send C:\My Documents to the Wizard and press 3 to change the Working Directory from C:\WINDOWS to C:\My Documents. Send C:\CLU and press 4 to make it the Location. Press Y to make "SC to NOTEPAD.EXE" in C:\CLU. Repeat for WORDPAD.EXE to make "SC to WORDPAD.EXE" in C:\CLU. Look at the Program Properties of these shortcuts. VBS correctly adds quote characters to long names and names with spaces. Test both shortcuts.

However, for MS-DOS based programs like Qbasic, VBS puts in alias paths. To see this make "
SC to Qbasic.exe" with the C:\My Documents Working Directory and the C:\CLU Location. Look at the shortcut's Program Properties. Replace the MYDOCU~1 alias with "My Documents" including the quote characters. Test the shortcut.

The "Windows Wizard"

To invoke this Wizard (Figure 9), right click a blank part of any directory, point to "New" and click "Shortcut". Check that My Documents doesn't have a file named
NOTEPAD.EXE and then open the "Windows Wizard" in My Documents. Make an example shortcut to NOTEPAD.EXE.

  1. Either type 
    C:\WINDOWS\NOTEPAD.EXE or click [Browse], Scroll to Windows, 
    and click [Open]. Scroll to Notepad.exe and click [Open].
  2. Click [Next>, accept the name "Notepad.exe" or type a name of your choice. Click [Finish].
The new shortcut in "My Documents" is highlighted ready to be customised (NB. The Working Directory is always the same as the Command Line path). Check the Program Properties. Then repeat for WORDPAD.EXE.

Reprinted from the June 2002 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]