VBScript, WMI, and ADSI Unleashed: Using VBScript, WMI, and ADSI to Automate Windows Administration

Fileaze banner

 

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.

 

  1. Data & Variables
  2. Databases
  3. Working with Files
  4. Working with Folders
  5. Internet
  6. Inventory
  7. MultiMedia
  8. Network
  9. Object Browsers
  10. OLE Automation
  11. Printing
  12. Processes & Services
  13. Registry
  14. Regular Expressions
  15. Shortcuts
  16. Time & Date
  17. User Interaction

 

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. Pad Strings
     

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
     

Back to the top of this page . . .

 

Working with Files

  1. CAB Files
    1. MakeCab
    2. Extract CAB files with System.Shell Folders' CopyHere method
     
  2. INI Files
    1. ReadINI
    2. WriteINI
    3. DeleteINI
    4. Sample Script
     
  3. MD5 Checksums
    1. X-MD5
     
  4. Encode or Encrypt Files
    1. X-Base64
    2. XOR
     
  5. Self-Destruct
    1. Self-Destruct by Denis St-Pierre
     
  6. XML Files
    1. XMLDOM
     
  7. 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
     

Back to the top of this page . . .

 

Working with Folders

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

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. Query freedb.org CD Database
    1. FREEDBControl.uFREEDB
     
  5. Query WhoIs Database
    1. InternetExplorer.Application (Function)
    2. InternetExplorer.Application (Class)
    3. InternetExplorer.Application (WSC)
     
  6. Query Yahoo Financial Pages for Currency Exchange Rates
    1. WinHTTP (Function)
    2. WinHTTP (Class)
     
  7. 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)
     
  8. Check if Websites are Up-And-Running
    1. WinHTTP
    2. X-HTTP
     

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
     

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. Ping Computers
    1. Win32_PingStatus
     
  2. Retrieve Names
    1. User Name
      1. Environment Variable
      2. WshNetwork
      3. ADSI (WinNTSystemInfo)
      4. ADSI (ADSystemInfo)
      5. WMI (Win32_ComputerSystem)
       
    2. Computer Name
      1. Environment Variable
      2. WshNetwork
      3. SHGINA.DLL (Shell.LocalMachine)
      4. ADSI (WinNTSystemInfo)
      5. ADSI (ADSystemInfo)
      6. WMI (Win32_ComputerSystem)
       
    3. Computer Domain or Workgroup Name
      1. WMI (Win32_ComputerSystem)
      2. WMI (Win32_NTDomain)
       
    4. User Domain Name
      1. Environment Variable
      2. WshNetwork
      3. ADSI (WinNTSystemInfo)
      4. ADSI (ADSystemInfo)
       
     
  3. Wake Up Computers
    1. UltraWOL
     

Back to the top of this page . . .

 

Object Browsers

  1. Editors, IDEs & Object Browsers

Back to the top of this page . . .

 

OLE Automation

SnagIt
  1. 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
     
  2. 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
     
  3. An introduction to Automating OpenOffice.org
     
  4. Automate burning CDROMs and DVDs with IMAPI (lots of working sample scripts)
     
  5. Automate SnagIt screen captures

Back to the top of this page . . .

 

Printing

  1. Print Files
    1. Shell.Application
     

Back to the top of this page . . .

 

Processes & Services

  1. Processes
    1. Kill Processes by Denis St-Pierre
     
  2. Services
    1. Restart Services
     

Back to the top of this page . . .

 

Registry

  1. WMI StdRegProv
     
  2. 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. File Open Dialog
    1. UserAccounts.CommonDialog
    2. SAFRCFileDlg.FileOpen
     
  5. File Save Dialog
    1. SAFRCFileDlg.FileSave
     
  6. Login Dialog
    1. InternetExplorer.Application
     
  7. Prompt for Passwords
    1. ScriptPW.Password
    2. InternetExplorer.Application
     
  8. Progress Bars
    1. Copy Folders with Progress Bar using System.Shell Folders' CopyHere method
     
  9. Prompt for User Input
    1. WSH (StdIn or InputBox)
    2. InternetExplorer.Application
     

Back to the top of this page . . .