Rob van der Woude's Scripting Pages

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

  1. Debugging Your Scripts

Back to the top of this page . . .

 

Data & Variables

  1. Arrays, ArrayLists, SortedLists & Dictionary Objects
    1. Array
      1. Sort
      2. Display
      3. Reverse
    2. ArrayList
    3. SortedList
    4. Dictionary (also known as "associative array")
     
  2. Integers
    1. Integer Divide methods
     
  3. Random Numbers
    1. Standard VBScript
    2. .NET Framework
    3. True Random Numbers (Functions)
    4. True Random Numbers (Class)
    5. True Random Numbers (WSC)
     
  4. Roman Numerals
    1. Convert decimal numbers to Roman numerals
    2. Convert Roman numerals to decimal numbers
     
  5. Strings
    1. Denis St-Pierre's Val( ) function
    2. Pad Strings
    3. Related subject: file encryption
     
  6. Environment Variables
    1. WSH Shell Object
    2. WMI's Win32_Environment Class
     

Back to the top of this page . . .

 

Databases & Spreadsheets

  1. Read MS-Access databases (without using MS-Access)
     
  2. Read Excel files (without using Excel)
     
  3. XML Files
     
  4. Related Stuff: OLE Automation, The Connection Strings Reference

Back to the top of this page . . .

 

Scripting Engines

  1. Force a script to run in CSCRIPT
     

Back to the top of this page . . .

 

Working with Files

  1. Handle DOS Wildcards
    1. GetFiles
      use a regular expression to handle complex DOS wildcards
    2. GetFilesLE
      The simpler GetFilesLE (GetFiles Light Edition) handles file names only, whereas GetFiles handles file names with or without directories.
     
  2. CAB Files
    1. MakeCab
    2. Extract CAB files with System.Shell Folders' CopyHere method
     
  3. INI Files
    1. ReadINI
    2. WriteINI
    3. DeleteINI
    4. Sample Script
    5. KixINI.vbs
      demonstrates using KiXtart COM object in VBScript to read and write INI files
     
  4. MD5 Checksums
    1. X-MD5
     
  5. File Encoding
    1. Determine a file's text encoding by examining its Byte Order Mark (BOM)
      1. ADODB.Stream
       
    2. Convert ASCII to UTF-8
      1. ADODB.Stream
       
     
  6. Files Encryption
    1. X-Base64
    2. XOR
    3. Simple encryption/decryption script
      this sample script by Adriaan Westra encrypts/decrypts and scrambles/descrambles strings
     
  7. Self-Destruct
    1. Self-Destruct by Denis St-Pierre
     
  8. XML Files
    1. XMLDOM
     
  9. ZIP Files
    1. ZIP files and/or folders with X-ZIP
    2. ZIP folders with System.Shell Folders' CopyHere method
    3. UNZIP with X-ZIP
    4. UNZIP with System.Shell Folders' CopyHere method
     
  10. File Versions
    1. Shell.Application: ProductVersion
    2. WindowsInstaller.Installer: ProductVersion (*.msi)
    3. Scripting.FileSystemObject: GetFileVersion
    4. Scripting.FileSystemObject: DateLastModified
    5. Compare two version strings digit by digit
     

Back to the top of this page . . .

 

Working with Folders

  1. Create multi-level folders like CMD.EXE's MD does
     
  2. Delete folders, empty or not, like DOS' DELTREE does
     
  3. Cruto Creations' list of special folders and the VBScript code to get their paths and list their contents
     
  4. List of Special Folder Constants

Back to the top of this page . . .

 

Working with HTAs

  1. HTAs
     

Back to the top of this page . . .

 

Internet

  1. Download Files using HTTP
    1. WinHTTP
    2. X-HTTP
     
  2. Upload & Download Files using FTP
    1. ChilkatFTP
     
  3. Send e-Mail Messages
    1. CDOSYS
     
  4. Retrieve your WAN IP address
    1. WinHTTP
    2. XMLHTTP
    3. Internet Explorer
     
  5. Retrieve geographical information for host names or IP addresses
    1. GeoIP
     
  6. Use Google Calculator for unit conversion
    1. InternetExplorer.Application
     
  7. Read the Latest Software Version Number from a Web Page
    1. WinHTTP (hardcoded for Foxit Reader)
    2. WinHTTP (hardcoded for VBSEdit)
    3. WinHTTP (hardcoded for Revo Uninstaller)
     
  8. Query freedb.org CD Database
    1. FREEDBControl.uFREEDB
     
  9. Query WhoIs Database
    1. InternetExplorer.Application (Function)
    2. InternetExplorer.Application (Class)
    3. InternetExplorer.Application (WSC)
     
  10. Query Yahoo Financial Pages for Currency Exchange Rates
    1. WinHTTP (Function)
    2. WinHTTP (Class)
     
  11. True Random Numbers (use WinHTTP to retrieve true random integers from random.org)
    1. RndInt (function to retrieve a single random integer)
    2. RndIntArr (function to retrieve multiple random integers)
    3. Random (class to retrieve multiple random integers)
    4. Random.wsc (component to retrieve multiple random integers)
     
  12. Check if Websites are Up-And-Running
    1. WinHTTP
    2. X-HTTP
     
  13. User-Agent strings (Browser IDs)
     
  14. Related Stuff: Network Scripting

Back to the top of this page . . .

 

Inventory

  1. Check if a computer is a laptop
    1. Win32_Battery
     
  2. Generate an MSInfo report
    1. Msinfo32.MSInfo.1
     
  3. Related Stuff:
    1. Basic Hardware Inventory (HTA)
    2. Basic Software Inventory (HTA)
     

Back to the top of this page . . .

 

MultiMedia

  1. Query freedb.org CD Database
    1. FREEDBControl.uFREEDB
     

Back to the top of this page . . .

 

Network

  1. Resolve Host Names
    1. JavaWebstart
    2. System Scripting Runtime
     
  2. Retrieve IP Address(es)
    1. Win32_NetworkAdapterConfiguration
     
  3. Ping Computers
    1. Win32_PingStatus
    2. System Scripting Runtime
     
  4. Retrieve Names
    1. User Name
    2. Computer Name
    3. Host Names
    4. Computer Domain or Workgroup Name
    5. User Domain Name
     
  5. Login scripts
    1. Connect & disconnect network drives
    2. Connect & disconnect network printers and set the default printer
    3. Log computer access
    4. Log computer status & properties
     
  6. Retrieve your WAN IP address
    1. WinHTTP
    2. XMLHTTP
    3. Internet Explorer
     
  7. Retrieve MAC Address(es)
    1. Win32_NetworkAdapter
     
  8. Wake Up Computers
    1. UltraWOL
     
  9. Related Stuff: Internet Scripting

Back to the top of this page . . .

 

Object Browsers

  1. Editors, IDEs & Object Browsers

Back to the top of this page . . .

 

OLE Automation

  1. Automate Outlook
    1. Cleanup the Sent Items folder: delete all Sent Items that are over 2 weeks old
     
  2. Automate MS Word
    1. SaveAs: convert MS Word documents to HTML
    2. SaveAs: convert MS Word documents to PDF
    3. SaveAs: convert MS Word documents to RTF
    4. SaveAs: convert MS Word documents to XPS
    5. CapsLock: use MS Word (or WordPerfect) to check the CapsLock status
    6. More MS Office automation scripts at the Microsoft Technet ScriptCenter Office Space Archive
     
  3. Automate WordPerfect
    1. PublishPDF: convert WP documents to PDF
    2. SaveAs: convert WP documents to HTML
    3. Type: type and format text
    4. CapsLock: use WordPerfect (or MS Word) to check the CapsLock status
     
  4. Automate Excel
    1. XL2CSV: convert an Excel sheet to CSV.
    2. Create an Excel pie chart with directories of over 10MB (sample script by Adriaan Westra)
     
  5. Automate Quattro Pro
    1. QPro2Xls: convert a Quattro Pro spreadsheet to Excel
     
  6. An introduction to Automating OpenOffice.org
     
  7. Automate PhotoShop, sample scripts by Adriaan Westra
    1. Convert Nikon RAW images to JPG
    2. Create thumbnails with PhotoShop
    3. Create borders with PhotoShop
     
  8. Automate burning CDROMs and DVDs with IMAPI (lots of working sample scripts)
     
  9. Automate SnagIt screen captures
     
  10. Related Stuff: Databases, The Connection Strings Reference

Back to the top of this page . . .

 

Printing

  1. Print Files
    1. Shell.Application
     
  2. Manage Printers
    1. Network Printing Tools and Settings
    2. Create a Printer and Printer Port by Using PrinterAdmin (Prnadmin.dll)
     

Back to the top of this page . . .

 

Processes & Services

  1. Processes
    1. Kill Processes by Denis St-Pierre
    2. Get the Running Script's Process ID
     
  2. Services
    1. Restart Services
     

Back to the top of this page . . .

 

Registry

  1. WSH Shell (local only)
     
  2. WMI StdRegProv (local or remote)
     
  3. More information on the StdRegProv and WMI Registry functionality is available on MSDN
     

Back to the top of this page . . .

 

Regular Expressions

  1. Regular Expressions in VBScript
    1. The RegExp object
    2. Patterns
    3. Examples
     

Back to the top of this page . . .

 

Shortcuts

  1. Shortcuts
    1. GetShortcut by Denis St-Pierre
     

Back to the top of this page . . .

 

Time & Date

  1. Delays

Back to the top of this page . . .

 

User Interaction

  1. Browse Folder Dialog
    1. Shell.Application
     
  2. Change Default Printer Dialog
    1. MSComDlg.CommonDialog.1
     
  3. Change Password Dialog
    1. InternetExplorer.Application
     
  4. Select Folder Dialog
    1. Shell.Application
     
  5. File Open Dialog
    1. UserAccounts.CommonDialog
    2. SAFRCFileDlg.FileOpen
    3. InternetExplorer.Application
    4. Exec MSHTA by Rudi Degrande and Denis St-Pierre
     
  6. File Save Dialog
    1. SAFRCFileDlg.FileSave
     
  7. Login Dialog
    1. InternetExplorer.Application
     
  8. Prompt for Passwords
    1. ScriptPW.Password
    2. InternetExplorer.Application
     
  9. Progress Bars & Progress Messages
    1. Progress Messages by Denis St-Pierre
    2. Copy Folders with Progress Bar using System.Shell Folders' CopyHere method
     
  10. Prompt for User Input
    1. WSH (StdIn or InputBox)
    2. InternetExplorer.Application
     
  11. Buttons Dialogs
    1. InternetExplorer.Application by Denis St-Pierre
     

Back to the top of this page . . .

 

Windows Installer

  1. Get info from MSI files
    by Adriaan Westra
  2. Extract CAB files from MSI files
    by Adriaan Westra

Back to the top of this page . . .


page last modified: 2023-03-13; loaded in 0.0022 seconds