VBScript Tutorial for Beginners: Learn VBScript for Windows Automation
.vbs files still running in banks, insurance companies, and government systems. This tutorial focuses on those uses.
What Is VBScript?
VBScript (Microsoft Visual Basic Scripting Edition) is a scripting language created by Microsoft in 1996, modeled on the Visual Basic syntax. It runs through the Windows Script Host (WSH) — a built-in Windows component that executes scripts without compilation.
You write VBScript in a plain text file, save it with a .vbs extension, and Windows runs it. No compiler, no IDE required, no install. That simplicity is why VBScript became the standard automation tool for Windows administrators throughout the 2000s and is still common today.
Where VBScript Is Still Used in 2026
If you're learning VBScript today, it's almost certainly because of one of these:
| Use Case | What It Looks Like | Why VBScript |
|---|---|---|
| Windows Script Host | System administration scripts, scheduled tasks | Built into every Windows since 98, no install |
| Classic ASP | Legacy .asp web pages on IIS servers | Many enterprise applications never migrated |
| QTP / UFT testing | Automated UI test scripts | OpenText UFT One uses VBScript as its scripting engine |
| SCCM / MDT scripts | Windows deployment automation | Decades of existing infrastructure |
| Excel automation (legacy) | Office spreadsheet macros (older) | Cross-document scripts via WSH |
<script language="vbscript"> in a webpage, it's outdated — that won't run in Chrome, Firefox, Safari, or Edge.
Should You Learn VBScript or PowerShell?
Quick answer: PowerShell for anything new, VBScript only for maintenance. PowerShell is more powerful, better supported, and Microsoft's recommended path forward.
But there are real reasons to learn VBScript anyway:
- Legacy code maintenance. Millions of
.vbsfiles run production systems. Someone has to maintain them. That someone is well-paid because the talent pool is shrinking. - Classic ASP support. Some banks, government systems, and ERP applications still run on Classic ASP. They can't migrate easily and need VBScript developers.
- QTP/UFT tests. If you're in QA at an enterprise, your test framework is probably UFT, and UFT scripts are written in VBScript.
- Restricted environments. Some corporate environments disable PowerShell via group policy but allow Windows Script Host. VBScript still works there.
Microsoft Is Phasing VBScript Out
In May 2024, Microsoft announced VBScript will become a Features on Demand (FoD) component, then eventually be removed from Windows entirely. The timeline so far:
- Windows 11 24H2 (late 2024) — VBScript still installed by default but flagged as deprecated
- Future versions — VBScript becomes optional, must be enabled manually
- End of life — VBScript removed from Windows entirely (timeline not announced)
This makes VBScript skills both more valuable (legacy migrations need experts) and less worth specializing in (long-term outlook is decline). The sweet spot: learn enough VBScript to maintain existing code and help with PowerShell migrations.
Prerequisites
None. You don't need programming experience. You don't need any installs (if you're on Windows). You just need a text editor — Notepad works, but VS Code or Notepad++ is better.
Your First VBScript
Open Notepad. Type this:
MsgBox "Hello, VBScript!"
Save as hello.vbs on your Desktop. Make sure to:
- Change "Save as type" to "All Files" (otherwise Notepad adds
.txt) - Use the
.vbsextension exactly
Double-click the file. A message box pops up. That's it — you've run VBScript.
Two Ways to Run VBScript
Windows ships with two VBScript engines:
| Engine | Output | Best For |
|---|---|---|
wscript.exe | GUI dialogs (default) | End-user scripts, Windows shortcuts, scheduled tasks |
cscript.exe | Console output | Admin scripts, batch files, command-line use |
Run a script in console mode:
cscript hello.vbs
To set cscript as the default for all .vbs files:
cscript //h:cscript //s
VBScript Variables
VBScript is loosely typed — every variable is a Variant that can hold any data type.
Dim name, age, salary name = "Alice" age = 30 salary = 55000.50 MsgBox name & " is " & age & " years old"
The & operator concatenates strings. Use it instead of + for concatenation — + works on numbers but causes errors when mixing strings and numbers.
Option Explicit at the top. It forces you to declare every variable with Dim, catching typos before they become runtime bugs.
Option Explicit Dim userName userName = "Alice" MsgBox userName
Control Flow: If, Select, Loops
If statements
Dim hour hour = Hour(Now) If hour < 12 Then MsgBox "Good morning" ElseIf hour < 18 Then MsgBox "Good afternoon" Else MsgBox "Good evening" End If
Select Case (cleaner than long If chains)
Dim day day = WeekDay(Now) Select Case day Case 1: MsgBox "Sunday" Case 2: MsgBox "Monday" Case 3 To 5: MsgBox "Midweek" Case Else: MsgBox "Weekend" End Select
For loops
Dim i For i = 1 To 10 WScript.Echo "Counter: " & i Next
Do While / Do Until
Dim count count = 0 Do While count < 5 WScript.Echo count count = count + 1 Loop
Working with Files (The Real Reason to Learn VBScript)
This is where VBScript shines as a Windows admin tool. The FileSystemObject gives you full access to drives, folders, and files.
' Read every line of a text file Dim fso, file, line Set fso = CreateObject("Scripting.FileSystemObject") Set file = fso.OpenTextFile("C:\logs\error.log", 1) Do Until file.AtEndOfStream line = file.ReadLine WScript.Echo line Loop file.Close
Other common file operations:
' Check if a file exists If fso.FileExists("C:\data\config.ini") Then WScript.Echo "Found" End If ' List every file in a folder Dim folder, fileItem Set folder = fso.GetFolder("C:\reports") For Each fileItem In folder.Files WScript.Echo fileItem.Name & " - " & fileItem.Size & " bytes" Next ' Copy a file fso.CopyFile "C:\source\data.csv", "C:\backup\data.csv" ' Create a new file and write to it Set file = fso.CreateTextFile("C:\output\result.txt", True) file.WriteLine "Hello from VBScript" file.Close
Running Programs and Commands
The WScript.Shell object lets you execute any program or command-line tool:
Dim shell Set shell = CreateObject("WScript.Shell") ' Run Notepad shell.Run "notepad.exe" ' Run a command and wait for it to finish shell.Run "cmd /c dir C:\ > C:\filelist.txt", 0, True ' Read an environment variable Dim userProfile userProfile = shell.ExpandEnvironmentStrings("%USERPROFILE%") WScript.Echo userProfile
VBScript and Classic ASP
Classic ASP (Active Server Pages) uses VBScript as its server-side scripting language. ASP pages have a .asp extension and run on Microsoft IIS web servers. The syntax is identical to standalone VBScript, just wrapped in <% %> tags:
<%
Dim userName
userName = Request.Form("username")
If userName = "" Then
Response.Write "Please log in"
Else
Response.Write "Welcome, " & userName
End If
%>
.asp uses VBScript on the server.
Subroutines and Functions
Two ways to organize reusable code:
' Subroutine: does something, returns nothing Sub Greet(person) MsgBox "Hello, " & person End Sub Greet "Alice" ' Function: returns a value Function Multiply(a, b) Multiply = a * b End Function Dim result result = Multiply(6, 7) MsgBox result ' Shows 42
Error Handling
VBScript's error handling is unusual — there's no try/catch. You enable error suppression with On Error Resume Next, then check Err.Number:
On Error Resume Next Dim result result = 10 / 0 If Err.Number <> 0 Then WScript.Echo "Error: " & Err.Description Err.Clear End If On Error GoTo 0 ' Disable error suppression
Common Beginner Mistakes
1. Saving with the wrong file extension
Notepad's "Save as" defaults to .txt. If you save your script as hello.vbs.txt, Windows treats it as a text file. Always change "Save as type" to "All Files" before saving.
2. Forgetting Set with object variables
Regular variables use =. Object variables require the Set keyword:
' Wrong: fso = CreateObject("Scripting.FileSystemObject") ' Right: Set fso = CreateObject("Scripting.FileSystemObject")
3. Using + for string concatenation
Use & instead. + works on numbers but produces errors when mixing types:
' Risky: result = "Age: " + age ' Always safe: result = "Age: " & age
4. Confusing = and Set in conditions
VBScript uses = for both assignment and comparison. If x = 5 Then compares; x = 5 on its own line assigns. The language figures out which by context.
5. Running an old browser-based VBScript example
If you find a tutorial example like <script language="vbscript"> in HTML, that's the dead use case. It runs in Internet Explorer (which doesn't exist anymore), not in Chrome/Firefox/Edge. Stick to .vbs and .asp files.
Complete Learning Path
Work through the 21 chapters below in order. Estimated time: 30–45 minutes per chapter.
Week 1 — Foundations (Chapters 1–7)
Week 2 — Forms, Objects, and Standards (Chapters 8–14)
Week 3 — Strings, Math, Debugging, Advanced (Chapters 15–21)
Reference Material
VBScript Cheat Sheet
| Task | Code |
|---|---|
| Show a message | MsgBox "Hello" |
| Console output | WScript.Echo "Hello" |
| Get user input | name = InputBox("Your name?") |
| Concatenate strings | full = first & " " & last |
| Current date/time | now = Now |
| Run a program | CreateObject("WScript.Shell").Run "notepad.exe" |
| Read a file | Set f = fso.OpenTextFile("C:\file.txt", 1) |
| Write a file | Set f = fso.CreateTextFile("C:\out.txt", True) |
| File exists? | If fso.FileExists("C:\file.txt") Then |
| Loop a folder | For Each f In fso.GetFolder("C:\").Files |
| Pause execution | WScript.Sleep 1000 ' 1 second |
| Exit script | WScript.Quit |
| Suppress errors | On Error Resume Next |
| Check last error | If Err.Number <> 0 Then ... |
Frequently Asked Questions
Is VBScript still used in 2026?
Yes, in specific contexts. Browser-based VBScript is dead — no modern browser supports it. But VBScript is still actively used for Windows Script Host (WSH) automation, Classic ASP web applications, QTP/UFT test automation, and maintenance of legacy enterprise systems in banks, insurance, and government.
Should I learn VBScript or PowerShell?
PowerShell for new Windows automation projects — it's the modern, supported choice. VBScript only if you're maintaining existing .vbs scripts, working with Classic ASP, supporting QTP/UFT tests, or working in an environment that hasn't migrated yet. Many Windows admins know both.
Do I need to install anything to run VBScript?
No, if you're on Windows. The Windows Script Host (cscript.exe and wscript.exe) is built into every Windows version since Windows 98. Save your script as filename.vbs and double-click to run.
Is VBScript hard to learn?
VBScript is one of the easiest languages to learn. Syntax reads like English, there's no compilation, errors are forgiving, and you can run code immediately. Most people write working scripts within an hour.
What can VBScript do that PowerShell can't?
Almost nothing — PowerShell can do everything VBScript does and more. The exceptions are very specific legacy scenarios: maintaining Classic ASP code, working with QTP/UFT test scripts, or running on systems where PowerShell is restricted by group policy.
Will Microsoft remove VBScript from Windows?
Microsoft announced VBScript will become an on-demand feature in future Windows releases, eventually being removed entirely. The transition is gradual — VBScript still ships with current Windows versions, but Microsoft recommends migrating to PowerShell for new work.
Is VBScript the same as VBA?
No, but they're related. VBA (Visual Basic for Applications) runs inside Microsoft Office, with full access to those apps' object models. VBScript is a lighter version designed for scripting, missing some VBA features. Most code reads similarly between the two.
Do VBScript skills help me find a job?
Yes, in specific niches. Legacy maintenance roles at banks, insurance companies, and government agencies still require VBScript. Quality Assurance roles using QTP/UFT need it. Legacy specialist roles often pay above market because the talent pool is shrinking.
Start Chapter 1: Introducing VBScript →Last updated: April 25, 2026.