The book you need to succeed! Vbscript, jscript



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

226
 Part 
II
 
Windows JScript'>VBScript and JScript
JScript
deleteoption.js
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“StartMenu”)
fs = new ActiveXObject(“Scripting.FileSystemObject”);
f = fs.GetFile(smenu +”\\Notes.LNK”)
f.Delete();
Deleting menus
You can delete menus in much the same way as you delete menu options. However, you normally 
delete submenus of special folders rather than the special folders themselves. Also, when you create 
a menu for all users, you must delete the menu via the related special folder. For example, if you cre-
ate a submenu of AllUsersStartMenu, you must delete the submenu via the AllUsersStartMenu spe-
cial folder.
The first step in deleting a menu is to obtain a reference to the appropriate special folder, for example:
VBScript
Set ws = WScript.CreateObject(“WScript.Shell”)  
pmenu = ws.SpecialFolders (“Programs”)
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
pmenu = ws.SpecialFolders (“Programs”)
Afterward, use the 
DeleteFolder
 method to delete the submenu. Listing 11-11 shows how you can 
delete a submenu called Work Files under the Programs menu.
LISTING 11-11
Deleting a Menu
VBScript
deletemenu.vbs
Set ws = WScript.CreateObject(“WScript.Shell”)  
pmenu = ws.SpecialFolders (“Programs”)
Set fs = CreateObject(“Scripting.FileSystemObject”)  
fs.DeleteFolder(pmenu & “\Work Files”)
LISTING 11-10 
(continued)
86804c11.indd   226
86804c11.indd   226
1/21/09   1:26:39 PM
1/21/09   1:26:39 PM


227
 Confi guring Menus, Shortcuts, and Startup Applications 
11
JScript
deletemenu.js
var ws = WScript.CreateObject(“WScript.Shell”)
pmenu = ws.SpecialFolders (“Programs”)
fs = new ActiveXObject(“Scripting.FileSystemObject”);
var foldr = fs.DeleteFolder(pmenu + “\\Work Files”)
Adding and Removing Startup Applications
You specify applications that should be started after a user logs on by creating shortcuts in the 
AllUsersStartup and Startup folders. The AllUsersStartup folder sets startup applications for all users 
that log onto a system. The Startup folder sets startup applications for the current user.
Adding startup options
Because these shortcuts are used for automatic startup, the only option you need to set in most cases 
is the target path. Occasionally, you may also want to set a working directory for the application. The 
following example shows how you can set Internet Explorer as a startup application for all users:
VBScript
Set ws = WScript.CreateObject(“WScript.Shell”)  
smenu = ws.SpecialFolders(“AllUsersStartup”)  
Set scut = ws.CreateShortcut(smenu & “\Internet Explorer.LNK”)  
scut.TargetPath = “C:\Program Files\Plus!\Microsoft Internet\IEXPLORE.EXE”  
scut.Save
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“AllUsersStartup”)
var scut = ws.CreateShortcut(smenu + “\\Internet Explorer.LNK”)
scut.TargetPath = “C:\\Program Files\\Plus!\\Microsoft Internet\\IEXPLORE.
EXE”
scut.Save()
Removing startup options
If you later want to remove Internet Explorer as a startup application, you delete its related shortcut, 
like this:
VBScript
Dim ws, fs, f, smenu
Set ws = WScript.CreateObject(“WScript.Shell”)  
86804c11.indd   227
86804c11.indd   227
1/21/09   1:26:39 PM
1/21/09   1:26:39 PM


228
 Part 
II
 
Windows VBScript and JScript
Set smenu = ws.SpecialFolders(“AllUsersStartup”)
Set fs = CreateObject(“Scripting.FileSystemObject”)  
Set f = fs.GetFile(smenu & “\Internet Explorer.LNK”)
f.Delete
JScript
var ws = WScript.CreateObject(“WScript.Shell”)
smenu = ws.SpecialFolders(“AllUsersStartup”)
fs = new ActiveXObject(“Scripting.FileSystemObject”);
f = fs.GetFile(smenu +”\\Internet Explorer.LNK”)
f.Delete();
Moving startup options
You may want to move it to the Startup folder so that only the current user (rather than all users) 
runs the application on startup. To do this, you need to obtain a reference to the original folder and 
the destination folder, and then move the shortcut with the 
MoveFile
 method. Listing 11-12 shows 
how this can be handled.
LISTING 11-12
Moving a Shortcut to a New Location
VBScript
moveoption.vbs
Set ws = WScript.CreateObject(“WScript.Shell”) 
m1 = ws.SpecialFolders(“AllUsersStartup”)
m2 = ws.SpecialFolders(“Startup”)
orig = m1 & “\Internet Explorer.LNK”
dest = m2 & “\Internet Explorer.LNK”
Set fs = WScript.CreateObject(“Scripting.FileSystemObject”) 
fs.MoveFile orig, dest
JScript
moveoption.js
var ws = WScript.CreateObject(“WScript.Shell”)
m1 = ws.SpecialFolders(“AllUsersStartup”)
m2 = ws.SpecialFolders(“Startup”)
orig = m1 + \\Internet Explorer.LNK
dest = m2 + “\\Internet Explorer.LNK”
var fs = WScript.CreateObject(“Scripting.FileSystemObject”)
fs.MoveFile(orig, dest)
86804c11.indd   228
86804c11.indd   228
1/21/09   1:26:39 PM
1/21/09   1:26:39 PM


229
 Confi guring Menus, Shortcuts, and Startup Applications 
11
Summary
Use the techniques examined in this chapter any time you want to work with shortcuts, menus, and 
startup applications. Windows Script Host makes it possible to create and manage shortcuts in many 
different ways. Through shortcuts, you can manage menu options and startup applications as well.
86804c11.indd   229
86804c11.indd   229
1/21/09   1:26:39 PM
1/21/09   1:26:39 PM


Yüklə 12,95 Mb.

Dostları ilə paylaş:
1   ...   80   81   82   83   84   85   86   87   ...   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ə