By David Wiseman (Administrator)published 06 Feb 2008, modified 02 Mar 2009
My Rating:
Vote
Rating:
(1 votes)
Views:32350

VBScript (WSH) Introduction

What is VBScript?

VBScript started out as a client-side scripting language for web pages.  Microsoft later introduced Windows Script Host (WSH) to allow VBScript to be used outside internet explorer.  VBScript is now very popular among system administrators to automate various tasks.

How do I create a VBScript?

VBScript files are text files saved with a "*.VBS" file extension.  This means that you can create VBScript files using Notepad.  When you save a VBScript in notepad be sure to enclose the name in double quotes. e.g. "MyScript.vbs".  The double quotes will ensure that the file gets saved with the right extension (instead of MyScript.vbs.txt).

Although you can use notepad to develop VBScripts, programs like NotePad++ can help with VBScript development.  NotePad++ can highlight syntax and displays the line number, both of which can be useful when developing VBScripts.

How do I run a VBScript?

Example Script:
 

wscript.echo "Hello World!"

 

 VBScript supports two modes of execution - CSCRIPT and WSCRIPT. To run a script in WSCRIPT mode you can simply double-click the script file. Using the script example above, you would see the following output:

 

VBScript files often have "Wscript.Echo" statements to provide information to the user.  If a script has many "Wscript.Echo" statements or they are called in a loop, you might want to consider running the script in CSCRIPT mode.  To run a script in CSCRIPT mode, open a command console.  Change the directory to the folder where your script is located.  Type CSCRIPT "MyScript.vbs"

The output will look similar to the image below.  No confirmation is required.

 

You can also have the output directed to a text file when running in CSCRIPT mode:

CSCRIPT "MyScript.vbs" >> "scriptlog.txt"

VBScript Language

The VBScript language is very similar to Microsoft Visual Basic which is one of the reasons for its popularity.  It's also similar to VBA (Visual Basic for Applications) which is used to automate Microsoft Office. 

One of the key differences with VBScript is that it is a typeless language.  All variables are created as variants, which can be used to store any type of data.  In many other programming languages, including visual basic and VBA, you would declare a data type before storing a value in the variable. e.g.

DIM i as INTEGER
i = 1

The code above is not valid in VBscript as you would need to omit the "as INTEGER" from the variable declaration.  Another point worth noting is that you are not required to declare variables by default.  You could simply write the line of code "i=1" without declaring the "i" variable. 

I recommend that you use the "OPTION EXPLICT" statement at the top of all your scripts.  This statement will force you to declare all variables - although this might seem like extra work, it could save you loads of time when debugging scripts. e.g.

OPTION EXPLICIT
DIM i
i = 1

Further Reading

This has been a very quick introduction to VBScript.  For more information on VBScript and to learn how to program in VBScript I recommend the "Windows 2000 Scripting Guide".  This book is available FREE online:

Windows 2000 Scripting Guide 

Also, there are many examples of VBScripts on this website to help you get started.  Some of the scripts you will find are ready to use as is, others are very short snippets of code that are designed to be used as part of a larger script. 

Find a Script... 

Find a VBScript 

 




  Post Comment
Order By:  
User Comments
      
lcklck16
Posted On: 8/18/2017 4:15:20 AM

20170819 junda
michael kors canada
michael kors outlet online
ugg boots clearance
michael kors outlet
swarovski crystal
canada goose outlet
ray ban sunglasses
longchamp outlet online
coach outlet online
christian louboutin outlet
cheap ray bans
michael kors outlet online
ray ban sunglasses outlet
coach outlet online
nike air huarache
kobe 9 elite
coach outlet
coach outlet online
michael kors outlet store
roshe run
polo ralph lauren
tory burch outlet stores
michael kors outlet
ralph lauren polo
michael kors outlet online
cheap oakley sunglasses
fred perry polo
coach outlet online
tods outlet online
christian louboutin sale
ralph lauren outlet
ugg boots clearance
cheap oakley sunglasses
jerseys wholesale
ugg boots outlet
prada outlet online
nfl jersey
cheap ray ban sunglasses
polo pas cher
uggs outlet
polo outlet online
coach outlet online
coach outlet online
michael kors outlet online
polo ralph lauren
nba jerseys
nike shoes
cheap jordans
oakley sunglasses wholesale
snapbacks wholesale
air max 90
michael kors handbags clearance
max 1
coach outlet
snapbacks wholesale
mulberry handbags
mulberry bags
oakley sunglasses sale
burberry outlet sale
michael kors outlet online
polo outlet
ugg outlet,ugg outlet store,uggs outlet,ugg outlet online clearance,ugg outlet coupons,ugg outlet boots,ugg outlet online store,ugg outlet sale
nhl jerseys
canada goose outlet store
nike trainers uk
mbt shoes
christian louboutin outlet
Basketball Shoes
cheap ray ban sunglasses
fitflops uk
coach outlet online coach factory outlet
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
canada goose jackets on sale
tory burch outlet online
ferragamo shoes sale
ferragamo outlet
links of london jewellery
oakley sunglasses sale
pandora outlet
cheap ray ban sunglasses
ed hardy outlet
oakley sunglasses wholesale
coach outlet
true religion outlet uk
canada goose outlet
michael kors handbags
coach factory outlet
longchamp handbags
polo ralph lauren
canada goose jackets men
michael kors uk
cazal outlet
adidas nmd runner
christian louboutin
ugg boots clearance,ugg boots,ugg boots outlet,ugg boots for women,ugg boots on sale,ugg boots for men,ugg boots for kids,ugg boots clearance sale women,ugg boots clearance outlet
uggs outlet
mulberry handbags
coach factory outlet
ugg outlet store
oakley sunglasses wholesale
oakley sunglasses wholesale
ralph lauren?uk
true religion outlet
true religion outlet
mont blanc pens
michael kors outlet clearance
ray ban sunglasses
nike shoes
ugg clearance
michael kors handbags
uggs outlet
cheap jordans free shipping
fitflops uk
coach outlet store online
canada goose outlet
ferragamo shoes
coach outlet
coach outlet
air max trainers
michael kors outlet stores
cheap oakley sunglasses
canada goose outlet online
canada goose outlet store
michael kors outlet online
true religion outlet store
coach outlet
ugg outlet online
michael kors outlet clearance
adidas shoes
uggs outlet
michael kors outlet online
kobe shoes
longchamp handbags
air max 90
chrome hearts outlet
ugg outlet stores
cheap nfl jerseys
coach outlet online
michael kors outlet clearance
michael kors handbags outlet
michael kors uk
birkenstock shoes
ralph lauren uk
christian louboutin shoes
cheap oakley sunglasses
cheap ray ban sunglasses
adidas nmd
air force 1 shoes
swarovski jewellery
tory burch outlet online
coach outlet
cheap jordan shoes
longchamp handbags
oakley sunglasses wholesale
cheap oakley sunglasses
polo outlet stores
adidas shoes
michael kors outlet
christian louboutin
christian louboutin uk
ugg clearance
ralph lauren uk
coach outlet online
canada goose outlet
oakley sunglasses
coach outlet store online
pandora jewelry
chrome hearts online store
swarovski outlet
burberry outlet store
ralph?lauren
mbt shoes outlet
true religion canada
true religion jeans sale
vans outlet
coach outlet store online
adidas shoes
canada goose jackets for women
kate spade handbags
coach outlet online coach factory outlet
christian louboutin sale
foamposite shoes
hermes belts
cheap ray bans
coach outlet online
uggs outlet
ugg boots australia
polo outlet
ugg boots outlet
nfl jersey wholesale
michael kors outlet online
oakley sunglasses wholesale
cheap michael kors handbags
mlb jerseys
prada outlet
cheap jordans
fitflops
nike free running
mlb jerseys
michael kors outlet clearance
pandora jewellery
nike outlet store online
air max 90
herve leger dresses
salomon outlet
michael kors outlet clearance
oakley sunglasses
cheap soccer jerseys
ugg outlet
ralph lauren polo
nike shoes outlet
nike air huarache
adidas uk store
christian louboutin shoes
longchamp outlet
cheap uggs outlet,cheap uggs for sale,cheap ugg boots,cheap uggs for kids,cheap uggs for women,cheap uggs bailey bow,cheap uggs china,cheap uggs for men,cheap uggs for girls,cheap uggs boots for women
ugg boots,ugg boots outlet,cheap uggs boots,ugg boots for women,ugg boots on sale,ugg boots clearance,ugg boots clearance sale women,ugg boots clearance outlet,ugg boots for men,ugg boots for kids
ugg outlet store
coach outlet store online
uggs outlet
lebron shoes
ugg outlet
canada goose jackets
pandora outlet
thomas sabo charms
mont blanc outlet
adidas outlet
ralph lauren uk
pandora outlet
polo outlet store
michael kors outlet clearance
coach outlet online
coach outlet online
max 90
coach outlet clearance
nike air max 1
michael kors outlet
ralph lauren outlet
oakley sunglasses wholesale
puma shoes
cheap uggs
mac tools
cheap jerseys wholesale
kate spade uk
canada goose jackets outlet
mulberry outlet,mulberry handbags outlet
ralph lauren
true religion jeans
air max 90
michael kors outlet clearance
ray ban sunglasses uk
ysl outlet online
polo outlet stores
ralph lauren outlet
cheap football shirts
nike outlet store online
ugg boots clearance
michael kors outlet clearance
michael kors outlet clearance
longchamp handbags
christian louboutin shoes
cheap ray ban sunglasses
ray ban sunglasses uk
coach outlet store online
ralph lauren
michael kors outlet clearance
ray-ban sunglasses
longchamp outlet
ralph lauren
coach outlet
nike store uk
ugg outlet,ugg outlet sale,uggs outlet,ugg outlet online clearance,ugg outlet store,ugg outlet coupons,ugg outlet boots,ugg outlet online store
canada goose coats
coach outlet
coach outlet online
coach outlet
michael kors outlet online
christian louboutin shoes
tory burch sandals
michael kors outlet online
coach factory outlet
kd shoes
ugg outlet clearance,ugg outlet online clearance,ugg outlet,uggs outlet,ugg outlet store,ugg outlet coupons,ugg outlet boots,ugg outlet online store,ugg outlet sale
oakley sunglasses wholesale
michael kors outlet
nhl jerseys wholesale
coach factory outlet
michael kors outlet
ray ban sunglasses
hermes outlet store
mulberry bags
new balance outlet
coach outlet clearance
fitflops sale clearance
jordan shoes
coach factory outlet
jordan 4
true religion jeans outlet
canada goose uk
ray ban sunglasses wholesale
coach outlet
cheap ray ban sunglasses
michael kors outlet online
michael kors outlet clearance
soccer jerseys wholesale
reebok shoes
uggs outlet
ferragamo shoes
nike air max 90
michael kors handbags outlet
air max shoes
coach outlet
coach outlet store online
prada outlet
cheap jordans for sale
michael kors bags
ugg boots clearance
polo outlet
coach outlet online
michael kors handbags
nike roshe run
polo ralph lauren
ferragamo outlet
polo ralph lauren
cheap oakley sunglasses
mulberry handbags
ugg boots outlet
michael kors outlet store
cheap oakley sunglasses
coach outlet store online
reebok shoes
bottega veneta outlet online
ugg outlet clearance
polo ralph lauren outlet
coach outlet
michael kors outlet clearance
cheap oakley sunglasses
michael kors outlet online
christian louboutin shoes
coach factory outlet
coach outlet
hermes outlet
ugg outlet online
ralph lauren outlet
ralph?lauren?polo?shirts
canada goose jackets
mac outlet
ralph lauren shirts
burberry canada
mcm backpacks
prada sunglasses for women
ugg boots for women,ugg boots,ugg boots outlet,ugg boots on sale,ugg boots clearance,ugg boots for men,ugg boots for kids,ugg boots clearance sale women,ugg boots clearance outlet
ray ban wayfarer
Nike Free shoes
michael kors handbags
true religion outlet
yeezy boost 350
oakley sunglasses wholesale
nfl jerseys
nfl jersey wholesale
nike shoes uk
ugg boots clearance
canada goose jackets
ralph lauren outlet stores
cheap nfl jerseys
yeezy boost
nike uk store
coach outlet clearance
nfl jerseys
oakley sunglasses wholesale
ralph lauren outlet
true religion jeans
marc jacobs sale
fitflops sale clearance
longchamp bags
michael kors outlet
coach outlet
oakley sunglasses sale
lacoste outlet
true religion outlet
polo ralph lauren outlet
fitflops
michael kors outlet clearance
michael kors handbags
tory burch handbags
nike air max 90
hermes birkin bag
coach outlet online
michael kors outlet online
true religion uk
adidas shoes
adidas outlet
tory burch outlet
cheap jordan shoes
ugg boots,ugg boots outlet,ugg boots for women,ugg boots on sale,ugg boots clearance,ugg boots for men,ugg boots for kids,ugg boots clearance sale women,ugg boots clearance outlet
cheap oakley sunglasses
kate spade
canada goose outlet
lebron shoes
mulberry outlet
pandora jewelery
true religion jeans
pandora charms
burberry outlet store
oakley sunglasses
cheap ray ban sunglasses
mulberry uk
cheap oakley sunglasses
cheap oakley sunglasses
kate spade outlet online
nike trainers
cheap oakley sunglasses
kate spade handbags
michael kors outlet
polo outlet
polo ralph lauren outlet
birkenstock shoes
nike shoes for women
ralph lauren polo
coach factory outlet
canada goose
coach outlet
soccer cleats
coach outlet store online
oakley sunglasses
true religion jeans sale
cheap oakley sunglasses
michael kors outlet online
coach outlet clearance
supra shoes sale
nba jerseys wholesale
swarovski uk
mulberry outlet
coach handbags outlet
swarovski jewelry
valentino shoes
mulberry handbags sale
michael kors outlet online
christian louboutin outlet
canada goose jackets
ugg outlet
michael kors outlet clearance
christian louboutin shoes
pandora bracelet
los angeles lakers
swarovski crystal
tory burch outlet online
ray-ban sunglasses
oakley sunglasses wholesale
lacoste polo
michael kors uk
polo ralph lauren outlet
adidas wings shoes
coach factory outlet
coach outlet online
ugg outlet,uggs outlet,ugg outlet online clearance,ugg outlet store,ugg outlet coupons,ugg outlet boots,ugg outlet online store,ugg outlet sale
polo ralph lauren outlet
coach outlet online
cheap jerseys wholesale
coach outlet online
coach factory outlet
coach outlet online
cheap nba jerseys
nike outle
giuseppe zanotti shoes
michael kors outlet
nike outlet online
ralph lauren outlet
christian louboutin sale
nike roshe run
coach factory outlet
ugg boots clearance
tory burch outlet online
nike blazer pas cher
ralph lauren outlet
kate spade uk
canada goose jackets
snapback hats
canada goose outlet
swarovski jewelry
ecco outlet
polo ralph lauren
oakley sunglasses sale
true religion jeans
cheap jordan shoes
michael kors outlet clearance
coach outlet online
fitflops sale clearance
uggs outlet
cheap oakley sunglasses
cheap ray ban sunglasses
lacoste pas cher
basketball shoes,basketball sneakers,lebron james shoes,sports shoes,kobe bryant shoes,kobe sneakers,nike basketball shoes,running shoes,mens sport shoes,nike shoes
canada goose outlet
cheap ray ban sunglasses
coach outlet store online
ugg boots outlet
michael kors outlet online
cheap oakley sunglasses
polo ralph lauren
ferragamo outlet
polo ralph lauren
michael kors wallets for women
nike outlet
ray ban sunglasses
canada goose jackets
lacoste shirts
cheap oakley sunglasses
cheap mlb jerseys
coach outlet
coach outlet store online
oakley sunglasses wholesale
cheap jordan shoes
michael kors outlet online
ugg outlet,ugg outlet clearance,uggs outlet,ugg outlet online clearance,ugg outlet store,ugg outlet online store,ugg outlet sale,ugg outlet coupons,ugg outlet boots
nike air max
true religion outlet
polo ralph lauren
oakley sunglasses wholesale
camisetas futbol baratas
mbt shoes outlet
michael kors outlet clearance
ferragamo shoes
ray bans
michael kors outlet clearance
coach factory outlet
coach outlet store
michael kors outlet clearance
ralph lauren outlet
coach outlet
air max 2015
fitflops sale clearance
ugg outlet store
pandora charms sale clearance
ralph lauren
michael kors uk
nike trainers
fitflops
cleveland cavaliers jerseys
coach outlet
cheap oakley sunglasses
michael kors outlet clearance
cheap nike shoes
cheap ray ban sunglasses
kobe bryants shoes
converse shoes sale
coach factory outlet
cheap oakley sunglasses
coach outlet online
michael kors factory outlet
christian louboutin sale
ray ban sunglasses outlet
pandora outlet
ralph lauren outlet