The book you need to succeed! Vbscript, jscript


 Confi guring Menus, Shortcuts, and Startup Applications



Yüklə 12,95 Mb.
Pdf görüntüsü
səhifə82/91
tarix07.11.2018
ölçüsü12,95 Mb.
#78682
1   ...   78   79   80   81   82   83   84   85   ...   91

219
 Confi guring Menus, Shortcuts, and Startup Applications 
11
scut.IconLocation = “iexplore.exe, 0”
scut.Save
JScript_workingdir.js'>JScript
licons.js
var ws = WScript.CreateObject(“WScript.Shell”)
pmenu = ws.SpecialFolders(“All(pmenu + “\\Current Script.LNK”)UsersPrograms”)
var scut = ws.CreateShortcut
scut.TargetPath = “%windir%\\notepad.exe“
scut.Arguments = “C:\\data\\curr.vbs”
scut.IconLocation = “iexplore.exe, 0” 
scut.Save()
Windows has to be able to fi nd the executable. If the executable can’t be found in the 
path, the icon can’t be set. In this case, enter the full path to the executable, like this:
scut.IconLocation = “C:\\Program Files\\Plus!\\Microsoft Internet\\
IEXPLORE.EXE, 0”
Setting working directories
The working directory sets the default directory for an application. This directory is used the first 
time you open or save files. Listing 11-6 creates a Start menu shortcut for Windows Notepad. The 
default directory is set to 
D:\working
.
VBScript_Set_fs_=_CreateObject(“Scripting.FileSystemObject”)_Set_foldr_=_fs.CreateFolder(pmenu__“\Work_Files”)_JScript'>VBScript_workingdir.vbs'>LISTING 11-6
Setting a Working Directory for Link Shortcuts
VBScript
workingdir.vbs
Set ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“StartMenu”)
Set scut = ws.CreateShortcut(smenu & “\Notepad for Working.LNK”)
scut.TargetPath = “%windir%\notepad.exe”
scut.WorkingDirectory = “C:\working”
scut.Save
JScript
workingdir.js
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“StartMenu”)
var scut = ws.CreateShortcut(smenu + “\\Notepad for Working.LNK”)
scut.TargetPath =”%windir%\\notepad.exe”
scut.WorkingDirectory = “C:\\working”
scut.Save()
TIP
TIP
86804c11.indd   219
86804c11.indd   219
1/21/09   1:26:38 PM
1/21/09   1:26:38 PM


220
 Part 
II
 
Windows VBScript and JScript
Setting properties for URL shortcuts
URL shortcuts open Internet documents in the appropriate application. For example, Web pages are 
opened in the default browser, such as Internet Explorer. With URL shortcuts, the only property you 
can use is 
TargetPath
, which sets the URL you want to use. Listing 11-7 creates a URL shortcut on 
the Start menu.
LISTING 11-7
Setting the Target Path for URL Shortcuts
VBScript
urlshortcut.vbs
Set ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“StartMenu”)
Set scut = ws.CreateShortcut(smenu & “\Cool Web Site.URL”)
scut.TargetPath = “http://www.centraldrive.com/”
scut.Save
JScript
urlshortcut.js
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“StartMenu”)
var scut = ws.CreateShortcut(smenu + “\\Cool Web Site.URL”)
scut.TargetPath =”http://www.centraldrive.com/”
scut.Save()
Managing Shortcuts and Menus
As you’ve seen, creating shortcuts isn’t that difficult. Now let’s extend what you’ve learned to new 
areas, such as creating, updating, and deleting menus.
Creating menus
Windows scripts can also create new menus. When you create menus, you add folders to existing 
special folders, such as Start or Programs. Start by obtaining a reference to the menu you want to 
add onto, like this:
VBScript
Set ws = WScript.CreateObject(“WScript.Shell”)
pmenu = ws.SpecialFolders (“Programs”)
86804c11.indd   220
86804c11.indd   220
1/21/09   1:26:38 PM
1/21/09   1:26:38 PM


221
 Confi guring Menus, Shortcuts, and Startup Applications 
11
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
pmenu = ws.SpecialFolders (“Programs”)
Then create a new menu by adding a folder to the special menu. The following example creates a 
submenu called Work Files under the Programs menu:
VBScript
Set fs = CreateObject(“Scripting.FileSystemObject”)
Set foldr = fs.CreateFolder(pmenu & “\Work Files”)
JScript
fs = new ActiveXObject(“Scripting.FileSystemObject”);
var foldr = fs.CreateFolder(pmenu + “\\Work Files”)
After you create the menu, you can add options to it. You do this by creating shortcuts that point to 
a location in the new menu. The following example creates a URL shortcut in the Work Files menu:
VBScript
Set ws = WScript.CreateObject(“WScript.Shell”)
Set scut = ws.CreateShortcut(pmenu & “\Work Files\CentralDrive.URL”)
scut.TargetPath = “http://www.centraldrive.com/”
scut.Save
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
var scut = ws.CreateShortcut(pmenu + “\\Work Files\\CentralDrive.URL”)
scut.TargetPath =”http://www.centraldrive.com/”
scut.Save()
Accessing and listing menu options
When you manage menus, you’ll often find that you need to display or manipulate all of the avail-
able options on a particular menu. Unfortunately, accessing a complete list of menu options is a bit 
more complex than one would imagine. For starters, you need to obtain a 
WshShell
 object and then 
use this object to access the special folder you want to work with, like this:
VBScript
Set ws = WScript.CreateObject(“WScript.Shell”)
 smenu = ws.SpecialFolders(mname)
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(mname)
86804c11.indd   221
86804c11.indd   221
1/21/09   1:26:38 PM
1/21/09   1:26:38 PM


Yüklə 12,95 Mb.

Dostları ilə paylaş:
1   ...   78   79   80   81   82   83   84   85   ...   91




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə