VBScript Scripting Techniques
This section is dedicated to VBScript scripting techniques, how-tos,
and "code snippets" for your "snippets library".
Not many complete ready-to-run script samples here, but demo scripts,
and code snippets that can be used to "glue" together your own full-blown
scripts.
I intend to gradually expand this library of VBScript snippets.
Debugging
Debugging Your Scripts
Back to the top of this page . . .
Data & Variables
Arrays, ArrayLists, SortedLists & Dictionary Objects
Array
Sort
Display
Reverse
ArrayList
SortedList
Dictionary
(also known as "associative array")
Integers
Integer Divide methods
Random Numbers
Standard VBScript
.NET Framework
True Random Numbers (Functions)
True Random Numbers (Class)
True Random Numbers (WSC )
Roman Numerals
Convert decimal numbers to Roman numerals
Convert Roman numerals to decimal numbers
Strings
Denis St-Pierre's Val( ) function
Pad Strings
Related subject: file encryption
Environment Variables
WSH Shell Object
WMI's Win32_Environment Class
Back to the top of this page . . .
Databases & Spreadsheets
Read MS-Access databases
(without using MS-Access)
Read Excel files
(without using Excel)
XML Files
Related Stuff: OLE Automation
Back to the top of this page . . .
Scripting Engines
Force a script to run in CSCRIPT
Back to the top of this page . . .
Working with Files
CAB Files
MakeCab
Extract CAB files with System.Shell Folders' CopyHere method
INI Files
ReadINI
WriteINI
DeleteINI
Sample Script
KixINI.vbs
demonstrates using KiXtart COM object in VBScript to read and write INI files
MD5 Checksums
X-MD5
Encode or Encrypt Files
X-Base64
XOR
Simple
encryption/decryption script
this sample script by Adriaan Westra encrypts/decrypts
and scrambles/descrambles strings
Convert ASCII to UTF-8
ADODB.Stream
Self-Destruct
Self-Destruct by Denis St-Pierre
XML Files
XMLDOM
ZIP Files
ZIP files and/or folders with X-ZIP
ZIP folders with System.Shell Folders' CopyHere method
UNZIP with X-ZIP
UNZIP with System.Shell Folders' CopyHere method
Back to the top of this page . . .
Working with Folders
Create multi-level folders like CMD.EXE's MD does
Delete folders, empty or not, like DOS' DELTREE does
Cruto Creations' list of
special
folders and the VBScript code to get their paths and list their contents
List of Special Folder Constants
Back to the top of this page . . .
Internet
Download Files using HTTP
WinHTTP
X-HTTP
Upload & Download Files using FTP
ChilkatFTP
SapienFTP
Send e-Mail Messages
CDOSYS
Retrieve your WAN IP address
WinHTTP
XMLHTTP
Internet Explorer
Retrieve geographical information for host names or IP addresses
GeoIP
Use Google Calculator for unit conversion
InternetExplorer.Application
Read the Latest Software Version Number from a Web Page
WinHTTP (hardcoded for Foxit Reader)
WinHTTP (hardcoded for VBSEdit)
WinHTTP (hardcoded for Revo Uninstaller)
Query freedb.org CD Database
FREEDBControl.uFREEDB
Query WhoIs Database
InternetExplorer.Application (Function)
InternetExplorer.Application (Class)
InternetExplorer.Application (WSC )
Query Yahoo Financial Pages for Currency Exchange Rates
WinHTTP (Function)
WinHTTP (Class)
True Random Numbers
(use WinHTTP to retrieve true random integers from
random.org )
RndInt (function to retrieve a single random integer)
RndIntArr (function to retrieve multiple random integers)
Random (class to retrieve multiple random integers)
Random.wsc (component to retrieve multiple random integers)
Check if Websites are Up-And-Running
WinHTTP
X-HTTP
User-Agent strings
(Browser IDs)
Related Stuff: Network Scripting
Back to the top of this page . . .
Inventory
Check if a computer is a laptop
Win32_Battery
Generate an MSInfo report
Msinfo32.MSInfo.1
Related Stuff:
Basic Hardware Inventory (HTA)
Basic Software Inventory (HTA)
Back to the top of this page . . .
Query freedb.org CD Database
FREEDBControl.uFREEDB
Back to the top of this page . . .
Network
Resolve Host Names
JavaWebstart
System Scripting Runtime
Retrieve IP Address(es)
Win32_NetworkAdapterConfiguration
Ping Computers
Win32_PingStatus
System Scripting Runtime
Retrieve Names
User Name
Computer Name
Host Names
Computer Domain or Workgroup Name
User Domain Name
Login scripts
Connect & disconnect network drives
Connect & disconnect network printers
and set the default printer
Log computer access
Log computer staus & properties
Retrieve your WAN IP address
WinHTTP
XMLHTTP
Internet Explorer
Retrieve MAC Address(es)
Win32_NetworkAdapter
Wake Up Computers
UltraWOL
Related Stuff: Internet Scripting
Back to the top of this page . . .
Object Browsers
Editors, IDEs & Object Browsers
Back to the top of this page . . .
OLE Automation
Automate Outlook
Cleanup the Sent Items folder :
delete all Sent Items that are over 2 weeks old
Automate MS Word
SaveAs : convert MS Word documents to HTML
SaveAs : convert MS Word documents to PDF
SaveAs : convert MS Word documents to RTF
SaveAs : convert MS Word documents to XPS
CapsLock : use MS Word (or WordPerfect) to check the CapsLock status
More MS Office automation scripts at the Microsoft Technet ScriptCenter
Office
Space Archive
Automate WordPerfect
PublishPDF : convert WP documents to PDF
SaveAs : convert WP documents to HTML
Type : type and format text
CapsLock : use WordPerfect (or MS Word) to check the CapsLock status
Automate Excel
XL2CSV : convert an Excel sheet to CSV.
Create an Excel pie chart with directories of over 10MB
(sample script by Adriaan Westra )
Automate Quattro Pro
QPro2Xls : convert a Quattro Pro spreadsheet to Excel
An introduction to
Automating
OpenOffice.org
Automate PhotoShop, sample scripts by
Adriaan Westra
Convert Nikon RAW images to JPG
Create thumbnails with PhotoShop
Create borders with PhotoShop
Automate burning CDROMs and DVDs with
IMAPI
(lots of working sample scripts)
Automate SnagIt screen captures
Related Stuff: Databases
Back to the top of this page . . .
Printing
Print Files
Shell.Application
Manage Printers
Network Printing Tools and Settings
Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll)
Back to the top of this page . . .
Processes & Services
Processes
Kill Processes by Denis St-Pierre
Services
Restart Services
Back to the top of this page . . .
Registry
WSH Shell (local only)
WMI StdRegProv (local or remote)
More information on the
StdRegProv
and
WMI
Registry functionality is available on MSDN
Back to the top of this page . . .
Regular Expressions
Regular Expressions in VBScript
The RegExp object
Patterns
Examples
Back to the top of this page . . .
Shortcuts
Shortcuts
GetShortcut by Denis St-Pierre
Back to the top of this page . . .
Time & Date
Delays
Back to the top of this page . . .
User Interaction
Browse Folder Dialog
Shell.Application
Change Default Printer Dialog
MSComDlg.CommonDialog.1
Change Password Dialog
InternetExplorer.Application
Select Folder Dialog
Shell.Application
File Open Dialog
UserAccounts.CommonDialog
SAFRCFileDlg.FileOpen
InternetExplorer.Application
File Save Dialog
SAFRCFileDlg.FileSave
Login Dialog
InternetExplorer.Application
Prompt for Passwords
ScriptPW.Password
InternetExplorer.Application
Progress Bars & Progress Messages
Progress Messages by Denis St-Pierre
Copy Folders with Progress Bar using System.Shell Folders' CopyHere method
Prompt for User Input
WSH (StdIn or InputBox)
InternetExplorer.Application
Buttons Dialogs
InternetExplorer.Application by Denis St-Pierre
Back to the top of this page . . .
Windows Installer
Get info from MSI files
by Adriaan Westra
Extract CAB files from MSI files
by Adriaan Westra
Back to the top of this page . . .
page last uploaded:
4 March 2011, 12:56