This page will get you started writing VBScripts. I will explain
how to create, then and test a simple script. All you need is notepad. As you work through
the example, see how you manipulate the
Object (network) with the Method (Echo).Sample VBScript
The purpose of this script is to echo the name of
the User who is logged-on. Also VBScript will display the 'hostname' of
the Computer where the script is run.
' Guy Thomas October 2004
' Purpose of script to display the UserName and ComputerName
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name = "
& WshNetwork.ComputerName & VBCrLf _ & "User Name = " & WshNetwork.UserName
Learning Points
Note 1: VBCrLf is needed to force a carriage return in your
script.
Note 2: Underscore(_) is necessary because my script will not fit on one
line. ( The _ is not an error on your screen!)
˚
Testing:
Double click the .vbs file to test your script. VBScript will work
on Windows 2003, XP and Windows 2003 machines.
Bonus Sample 2
Stage 2) Let us ask the script to display the domain, naturally you must be logged to a domain
for this part to work!
Instructions:
Pre-requisites. You need a domain controller for this script to
work.
Copy and paste the script below into notepad.
Save the file with .vbs extension e.g. MyDomain.vbs
Double click and observe the message box
Add to your first script: & "Domain = " &
WshNetwork.UserDomain
Check the script below to see the extra: & vbCrLF _ on
the line above.
' VBScript.
' Guy Thomas October 2004
' Purpose of script to display the Domain name
Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "Computer Name = " & WshNetwork.ComputerName & vbCrLF _
& "User Name = " & WshNetwork.UserName & vbCrLf _ & "Domain = " & WshNetwork.UserDomain
Two ways to run your scripts.
Double-click the icon of the script. Useful for testing (I expect you have
done this already.)
From the command line, type the name of the script. This is what
will happen at logon.
The extra features you get in your eBook
include, more pages full of detailed examples. Also, ten 'how to...'
sections, with screen shots showing which menus to use. Go for Guy's
eBook - and get a printable version with copy enabled and no expiry date.