Scripting and automation using VB script
Here at this page, you can have a basic knowledge of scripting using visual basic.VB Script is a scripting language using which you can automate several tasks. The scripting is useful where repeatative tasks are to be performed more frequently. We can drastically reduce time and effort using VB Script for any operations.
We will see several examples of VB script.For Eg.
-
To start applications automatically that you start everytime you log on to system
There are so many apps that we start once we log on to our system.Eg. MS outlook, Internet explorer and many more.Instead of starting them one by one manually you can start them automatically using simple trick.Simply place the apps executables in the startup folder"C:\Users\shankar_bhagat\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
-
To start MS outlook place this script in your startup folder
-
To start IE automatically, place this script in your startup folder
Sendkeys method of shell object is used to instruct system to send a keystroke.
Using this this we can make any key of the keyboard pressed. It works like the keys are pressed manually.
WshShell.SendKeys
Send one or more keystrokes to the active window as if they were typed at the keyboard. This method is similar to the VB SendKeys method.
Most keys can be represented by the character of the key itself.
E.g, the key sequence FRED can be represented simply by "FRED".
Some special keys, such as the control keys, function keys etc are encoded in a string enclosed by {braces}
See the table below
Key | SendKey | Equivalent Description |
~
!
^ + Alt Backspace Clear Delete Down End
Enter Escape F1 through F16
Page Down Space Tab |
{~}
{!}
{^}
{+}
{ALT}
{BACKSPACE}
{CLEAR}
{DELETE}
{DOWN}
{END}
{ENTER}
{ESCAPE}
{F1} through {F16}
{PGDN}
{SPACE}
{TAB} |
send a tilde (~)
send an exclamation point (!) send a caret (^)
send a plus sign (+)
send an Alt keystroke
send a Backspace keystroke
Clear the field
send a Delete keystroke
send a Down Arrow keystroke
send an End keystroke
send an Enter keystroke
send an Esc keystroke send the appropriate Function key
send a Page Down keystroke
send a Spacebar keystroke send a Tab keystroke |
SendKey
To specify keys combined with any combination of SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following:
To specify keys combined with any combination of SHIFT, CTRL, and ALT keys, precede the key code with one or more of the following:
For SHIFT prefix with +
For CTRL prefix with ^
For ALT prefix with %
See this Example
' Open notepad
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad", 9
' Give Notepad time to load
WScript.Sleep 500
'type in Hello World
WshShell.SendKeys "Hello World!"
WshShell.SendKeys "{ENTER}"