VB 教程

VBScript 是什么、能跑在哪、今天还有哪些用途。

Beginner
Key PointsVBScript 是微软的轻量脚本语言,跑在 WSH、经典 ASP 和(历史上的)IE 里,语法是 Visual Basic 的简化版。

VBScript 是什么

VBScript is a subset of Visual Basic with types, windows and controls stripped out, keeping only the core language. It produces no executable on its own — it needs a host: Windows Script Host, classic ASP on IIS, or historically Internet Explorer.

三种宿主

HostEntryUse
WSH (cscript)cscript //nologo x.vbs运维脚本、批量处理
WSH (wscript)双击 .vbs弹窗提示、静默运行
ASP<% %> 里老式 Web 页面
IE<script language="VBScript">已废弃,仅 IE 支持

第一个脚本

VBSCRIPT
' hello.vbs
Dim name
name = "World"

WScript.Echo "Hello, " & name
WScript.Echo "当前时间:" & Now()
Bash
cscript //nologo hello.vbs
Output
Hello, World
当前时间:2026/11/3 14:25:09

WScript.Echo prints to the console under cscript and shows a message box under wscript. The same script behaves differently depending on how it is launched — the most common surprise when debugging WSH scripts.

今天还值得学吗

SituationVerdict
Maintaining old ASP sites要 —— 服务端逻辑全是 VBScript
Windows admin scripts可以,但 PowerShell 更强
New automation用 PowerShell 或 Python
Client-side scripting不要 —— 只有 IE 支持
VBScript still works on Windows 11 but Microsoft lists it as a deprecated feature that may be removed. No new project should depend on it; it matters only for maintaining existing systems.

学习路线

  1. 语法 —— 变量、运算符、条件、循环
  2. 过程 —— Sub 与 Function、参数传递
  3. 内置函数 —— 字符串、日期、类型转换
  4. 宿主对象 —— WScript、FileSystemObject
  5. 实战 —— 批量改名、日志分析、定时任务

Friends & Partners