Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Note: The default action of Drag/Drop varies depending on the context (for example: between the same or different hard drives or between the Start menu and the desktop). You can override the default Drag/Drop action by holding the <Alt>, <Ctrl> or <Shift> as you Drag/Drop. <Alt> Drag/Drop always creates a link (or shortcut), <Ctrl> Drag/Drop always performs a copy operation and <Shift> Drag/Drop always performs a move operation.
Right-click on the new Command Prompt desktop icon and select Properties.
Click the Advanced button to open the Advanced dialog. Check the box Run as administrator. Click OK to close the Advanced dialog. Click Apply then OK to in the Properties
CLI_NotePad++_Settings.docx 1 Revision Date: 1111
dialog to youre your changes. Now every time you open the Command Prompt link you will run the CLI as administrator.
CLI_NotePad++_Settings.docx
Click OK to exit the Advanced dialog. In the Properties dialog, click Apply then OK to accept the changes and close the Properties dialog.
3 Revision Date: 1111
CLI_NotePad++_Settings.docx
Note: The advantage of using Remember last used directory is the path used by NotePad++ will default to the last file you opened using File/Open. This will allow us th Run or Execute our scripts with having to specify an explicit path. Open the Language Menu/Tab Settings tab and change the Tab size: to 2 and check box Replace by space.
Open the Backup/Auto-Completion tab and check the Enable auto-completion on each input box for Function completion. Also check the Function parameters hint on input box.
CLI_NotePad++_Settings.docx
Under Language, select VB / VBS. Note that we can set individual fonts and colors for the styles: DEFAULT, COMMENT, NUMBER, WORD, STRING, PREPROCESSOR, OPERATOR, DATE
If you cannot find the color you need in the standard palette, click the More Colours button. Click and Drag your mouse across the color spectrum and click on the color you want to use. You can adjust the brightness (Luminosity) level of your color by sliding up or down with your mouse.
To make the configuration easier, just choose the closest color found in the standard palette.
For DEFAULT, set the color to Black, the Font to Consolas and the Font size to 10.
CLI_NotePad++_Settings.docx
For COMMENT, set the color Dark Green, the font to Consolas, Italic and the Font size to 10.
For NUMBER, set the color to Dark Purple, the Font to Consolas and the Font size to 10.
For WORD, set the color to Medium Blue, the Font to Consolas and the Font size to 10.
For STRING, set the color to Red, the Font to Consolas and the Font size to 10.
CLI_NotePad++_Settings.docx
For PREPROCESSOR, set the color to Red, the Font to Consolas and the Font size to 10.
For OPERATOR, set the color to Dark Blue, the Font to Consolas Bold and the Font size to 10.
For DATE, set the color to Green, the Font to Consolas and the Font size to 10.
CLI_NotePad++_Settings.docx
In the Available tab, check the Explorer plugin. Scroll down the list of plugins and also check the NppExec plugin. Click the Install button to install the plugins into NotePad++.
NppExec provides a built-in Console for running VBScripts with cscript. This will allow you to run your script and test for errors without leaving NotePad++. You can also remove the WScript.Sleep( ) and WScript.StdIn.Read(1) statements if they were used to prevent the Console window from closing. The NppExec Console window will not close until you choose to close it from the toolbar. The NppExec dialog is activated with an <F6> keypress. The last program can be run again by pressing <Ctrl><F6>. The Console font should be changed to Consolas Bold 10 pt. using the Plugins menu. The NppExec console can be docked anywhere on the Notepad++ application window or it could be left floating on the desktop. Explorer provides a navigation pane and contents pane (similar to Windows Explorer) that can be used to find your VBScript sourcecode files. Double-clicking on a file in the contents pane will open the file in the NotePad++ editor window. The Explorer hotkey can be changed from <Ctrl><Alt><Shift>E to <Ctrl>E using the Macro menu. Like the NppExec Console, Explorer can be docked anywhere on the Notepad++ application window or it could be left floating on the desktop.
CLI_NotePad++_Settings.docx
After the NppExec and Explorer plugins have been installed and NotePad++ has been restarted, Use the Plugins menu as shown below to change the Console font to Consolas Bold 10 pt. Click OK to record the changes.
To change the Explorer hotkey using the Macro Modify ShortCut/Delete Macro menu option. This will open the Shortcut mapper dialog. Open the Plugin commands tab and select Explorer. Click the Modify button and remove the check marks for the ALT and SHIFT shift keys. Click OK and close the Shortcut mapper dialog. With your cursor in the Editor window, press <Ctrl>E to verify that the new Explorer hotkey is enabled. Move the cursor back to the Editor windows and press <Ctrl>E again to close Explorer.
CLI_NotePad++_Settings.docx
Open the Windows CLI using the desktop link (or shortcut) you created in Task 1. Change Directory (CD) to C:\Scripts use the dir command to verify the sourcecode file is there. Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. C:\Windows\system32>cd \Scripts C:\Scripts>dir EchoDemo.vbs Directory of C:\Scripts 11/14/2011 11:55 AM 1 File(s) 183 EchoDemo.vbs 183 bytes
C:\Scripts> VBScript programs are not standalone programs like those created by a C++ compiler. C++ programs can be compiled and linked to create a standalone executable (.exe) program. VBScript programs must be run using an Windows Scripting Host (WSH) interpreter. The two WSH interpreters are cscript and wscript. Cscript sends program output to the Command Line Interface (or console) whereas wscript sends program outout to a PopUp Window. Most of the programs we will write will use cscript. Assuming that we want to run the VBScript program EchoDemo.vbs, we would enter the following commands: C:\Scripts>cscript EchoDemo.vbs or C:\Scripts>wscript EchoDemo.vbs
CLI_NotePad++_Settings.docx 10 Revision Date: 1111
Run the EchoDemo.vbs program using cscript first and then wscript. You should get the outputs shown below:
If you enter the VBScript program name in the Windows CLI without specifying the interpreter, the wscript Interpreter will be used by default. Type EchoDemo.vbs and verify this.
CLI_NotePad++_Settings.docx
11
If you want to use the cscript WSH interpreter, you will have to type cscript before you type the path and VBScript filename as shown below. Click the Run button. What did you see? What you should see is a console window flash on the screen and then quickly disappear. The EchoDemo.vbs program did run, but when the program ended, the console window closed.
CLI_NotePad++_Settings.docx
12
To run a program with cscript in NotePad++ using the Run dialog, you need a statement to pause the program before the console window closes. There are two ways to pause or delay closing the NotePad++ console window. The first statement will pause the program until the user presses the <Enter> key. Modify your EchoDemo.vbs program as shown below. A WScript.Echo statement is added on line 10 to prompt the use to Press <Enter> to End Program. The WScript.StdIn.Read(1) statement in line 11 pauses the program execution until the user presses the <Enter> key. Save the program using <Ctrl>S and press <F5> <Enter> to run the program again.
Now our revised EchoDemo.vbs program can be run using cscript in NotePad++ Run dialog. WScript.StdIn.Read(1) is very effective while you are developing a console program so you dont have to go back and forth between NotePad++ and the Windows CLI. Note: If the program being run from NotePad++ is a lab assignment, you can use your mouse to click and drag over the console text you want to copy and press <Enter> to put the console text into the clipboard.
Another available option is to use the WScript.Sleep(6000) to keep the NotePad++ console window open for an additional 6000 milliseconds (6 seconds). The Sleep value can be any value of delay you need in milliseconds (seconds * 1000 = milliseconds) . Delete lines 10 and 11 from the EchoDemo.vbs program in NotePad++ and add the following line 10, save your program <Ctrl>S and run the program with <F5> <Enter>. The console window will now remain open for 6 seconds before it closes.
CLI_NotePad++_Settings.docx
13
Introduce an error into the program in line 7 by misspelling the Echo method as Eccho. Save the program <Ctrl>S. Run the program using <F5> <Enter>.
Even though we had a 6 second Sleep method in our program, the console flashed on and closed immediately. If we are running a console VBScript program in NotePad++ and we have used WScript.StdIn.Read(1) or WScript.Sleep(6000) to pause the console window; and the console window still flashes and closes immediately, that is a clear indication of an error in our program. When this happens, analyze your program in NotePad++ for syntax errors including misspelled commands, strings with a missing , etc. If you find an error, correct it, save your program and try to run it again. If you cant find the error by inspecting your source code, you will need to trouble-shoot your program from the Windows CLI.
Minimize, but dont close NotePad++. Open the Windows CLI using the desktop link (or shortcut) you created in Task 1. Change Directory (CD) to C:\Scripts. Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. C:\Windows\system32>cd \Scripts C:\Scripts>
CLI_NotePad++_Settings.docx
14
Run your program and look for error messages. In the run below, an error has been detected in line 7, column 1 of the source code. Even though the column number is specified as 1, the error could be anywhere in line 7. C:\Scripts>cscript EchoDemo.vbs Microsoft (R) Windows Script Host Version 5.8 Copyright (C) Microsoft Corporation. All rights reserved. C:\Scripts\EchoDemo.vbs(7, 1) Microsoft VBScript runtime error: Object doesn't support this property or method: 'WScript.Eccho'
Read the error message to see if this helps to locate the error. The error message is Object doesnt support this property or method: WScript.Eccho. The object WScript does not contain a method called Eccho. Return to NotePad++ and correct the problem changing line 7 to:
Save your changes <Ctrl>S and re-run your program <F5><Enter>. Your program should now run as expected.
CLI_NotePad++_Settings.docx
15
This time we will run the program using the NppExec plugin. Press <F6> and enter cscript EchoDemo.vbs. Press OK to run the program. Notice that the program now runs in a built-in Console window that will not close until you click the Console toolbar button
CLI_NotePad++_Settings.docx
16
Put the error back into the program in line 7 by misspelling the Echo method as Eccho. Save the program <Ctrl>S.
Press <Ctrl><F6> to run your last NppExec command. This handle hotkey will run your program again without having to open the Execute dialog. You can see the error is detected in line 7.
Correct the error in line 7 and press <Ctrl>S to save your changes. Use wscript this time when you run EchoDemo.vbs with NppExec (<F6>). Just replace cscript with wscript and a pop-up windows will be displayed instead of a Console window. Please note that VBScript programs that are run using wscript cannot contain any WScript.StdOut and WScript.StdIn functions. Press <F6> and change the command to wscript. Click OK and observe the output.
CLI_NotePad++_Settings.docx
17
*WScript Object
Top-level object; forming the root of the object hierarchy.
Methods
WScript.ConnectObject(objectName,eventPrefix) WScript.CreateObject(objectName[,eventPrefix]) WScript.DisconnectObject(objectName) WScript.Echo([Arg1][,Arg2][,ArgN]) WScript.GetObject(pathToFileContainingAutomationObject[,programID][,eventPrefix]) WScript.Quit([errorCode]) WScript.Sleep(numberOfMilliseconds)
Properties
WScript.Arguments (Returns: WshArguments collection) WScript.BuildVersion (Returns: integer) WScript.FullName (Returns: string; full path to host executable) WScript.Interactive (Returns: Boolean) WScript.Name (Returns: string; name of WScript object) WScript.Path (Returns: string; directory where script host resides) WScript.ScriptFullName(Returns: string; full path to current script) WScript.ScriptName (Returns: string; name of current script) WScript.StdErr (Returns: StdErr stream) WScript.StdIn (Returns: StdIn stream) WScript.StdOut (Returns: StdOut stream) WScript.Version (Returns: script; script host version)
* From Microsoft PowerShell, VBScript and JScript Bible, Wiley Publishing, 2009
CLI_NotePad++_Settings.docx
18