Updated June 2024 With Information For Windows 10+

VBScript Samples and Components


About VBScript

(Go directly to list of downloads.)

   VBScript (VBS) is a Windows scripting language: programming code that can be written as a text file and "executed" like an EXE file. VBS was originally developed in 1995 as a competitor to javascript in Netscape. At that time, the purpose of both script languages was to responsiveness in webpages by doing things like moving items or changing their visibility.

   With Windows98, Microsoft decided to develop the Windows Script Host (WSH), which allowed script to run on Windows. The general idea was to provide a GUI replacement for the largely outdated DOS scripting. With Windows being a graphical system, using a mouse, DOS was no longer a good fit. Microsoft transformed script from webpage code to a powerful programming language with one simple addition: CreateObject in VBScript and New ActiveXObject in javascript allowed scripting to load and use any compatible COM object. Programmers could write their own COM objects. But Windows is also full of COM objects. Internet Explorer, Windows Explorer, MS Office, Windows Installer... Most everything on Windows could be controlled by script.

   COM refers to component object model. It's essentially synonymous with ActiveX. ActiveX is primarily COM objects embedded in Internet Explorer. Microsoft developed a browser monopoly with IE in the late 90s by adding ActiveX. It meant that IE was vastly more powerful than Netscape. However, it also made IE vastly more unsafe because ActiveX was basically software programs running in the browser. Eventually Microsoft pulled back their support of ActiveX in webpages. By that time, corporate IT people were writing custom software using ActiveX components in IE, so Microsoft created the HTA file. An HTA is, for all practical purposes, just a renamed HTML file. But once it's an HTA there's no security restriction. HTAs provided a way to support browser-based software utilities on Windows while increasing security restrictions online.

   The scripts you'll find here include basic scripts to do things like count files or write text files. There are also a number of HTA files. Some are quite complex, such as the Windows Installer MSI file editor. Many use COM objects on Windows, such as IE, Windows Installer (MSI), Windows Image Acquisition (WIA), Windows Management Instrumentation (WMI) and so on.

Internet Explorer and Windows 10:

   IE is all but removed from Windows 10. As of late 2023 IE can't even be used without replacing ieframe.dll with an older version. Microsoft deliberately broke IE in order to push their Chrome Edge browser. However, the IE libraries are still present. HTAs still work. IE can still be started through script. So most of the scripts here are not affected by the changes to IE. To add the Run as Administrator option to context menus for VBS files, add the following key:
HKEY_CLASSES_ROOT\VBSFile\Shell\runas\Command
Set the default value to: C:\Windows\System32\WScript.exe "%1" %*
Similar can be done for HTA files.

   The most notable difference with Windows 10 vs older versions may be file restrictions. The default restrictions have gradually increased over time. If you don't disable UAC then you'll have warnings and restrictions. If you don't run as admin then you'll have problems.

The Future of VBScript

   Microsoft have "deprecated" VBScript as of 2024. The functionality is expected to be disabled by default in 2027. Deprecated, in programming jargon, means that functionality has not changed but that the deprecated item should no longer be regarded as the height of fashion by people who matter. "Deprecated" has no practical implications.

   Microsoft are pushing PowerShell (PS) as a replacement for VBScript. PS provides a great number of commandline operations that can be very useful on Windows. But PS is not a scripting replacement. It's more like an updated, expandable DOS, providing complex one-liner commands to accomplish Windows system management tasks. Microsoft actually developed PS to aid in attracting Linux server admins to Windows by giving them a set of console commands that looked similar to Linux counterparts.

   If you want to write software, you use a compilable programming language, like C++. If you want to be competent at system administration then it helps to collect various system tweaks docs and PS one-liners that can accomplish tasks. For example, most people can clean up multiple GBs of junk from their winsxs folder with just this simple command:
Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

   Scripting is a tool in between those other two. It's easier and quicker to write than compiled software, yet it can perform an endless of handy automations. It's more adaptable and flexible than one-liner commands. For example, you could write a simple script to change a particular word in each of 2,000 files and complete the task in a few seconds.

About the Resources Here

   In the links below you can find numerous script packages that start out with sample samples for the beginner but also include highly complex packages, such as the Windows Installer unpacker or the image editor and scanner interface. The titles may be difficult to understand in some cases, but the links lead to more involved explanations. Virtually all of the code here works on a standard Windows system, without needing any additional software. The components are free COM libraries that provide specialized functionality. Those need to be registered before use.

VBScript Programming Information

Software
  • WEB-ED Webpage and Scripting Editor 5   (Version 5.89. Now free. No strings. No spyware. No adware. No calling home. Period.)

WEB-ED Webpage and Scripting Editor is a code editor mainly for VBScript, HTML, DHTML, ASP, CSS, PHP, javascript. There are extra, specialized functions for HTML, VBS and CSS. VBScript colorcoding and debugging also work in HTML files (within SCRIPT or ASP tags).

WEB-ED was specifically designed to provide all the tools that a scripter or a web designer would need, if that person writes their own code. VBS functions include:
• Colorcoding of keywords, variables and comments.
• Code auto-completion popup for object methods and properties.
• Function parameters popup - shows sub and function parameters as you type for
   object methods, VBS methods, declared subs and functions - even when in external files.
• Object browser to research available objects.
• Configurable context help display for VBS methods.
• Auto-case adjustment of variables and keywords.
• Optional color printing of code.
• Snippet library for code storage.
• "Jump to last column" on carriage return for easier code indenting.
• Format debugging.
• Run scripts from the editor (and run in MS debugger if installed).
• Help file includes introduction to VBScript for beginners.

   All webpages and scripts on this website were written in the WEB-ED Editor.

Documentation:

   Getting help files for VBScript has become difficult. Some years ago, Microsoft stopped offering CHM files and SDKs for specific topics and began offering only gigantic SDK packages that include all help files in a newer HXS format. What docs do you need? Script56.chm covers basic Windows scripting. The DHTML help file covers IE/HTA scripting. Other specialized help files you might want would be msi.chm, wiaaut.chm, wmisdk.chm, etc. Those may be hard to find.

   If you would like to get up-to-date copies of CHM files for various Windows topics and can't find them, see the HXS to CHM Converter Utility. It's a small HTA utility. There are instructions on the page for downloading an SDK and ending up with usable CHM files.

Listing of Downloads

Scripts
Components
Components compatibility: DLLs will only work on Windows 32-bit.
* indicates also Vista/7/8/10/11 Win-64 compatibility.

Information
(Note: Please use a browser for download. This website blocks "download helper" software.)

Looking for something specific? Try the
Topic and Function Index Page


Information

About Using Classes
   Many of the scripts here use classes. This section is provided for people who may not be familiar with the use of classes in VBScript. (Though it is not necessary to understand classes in order to use them.)

   A class is a programming expedient that provides a way to package code as an independent unit for re-use. It is a self-contained unit that can be treated as an object. All you need to create a class is this:
  Class ClassName
       '-- class code goes here.
  End Class 
   Everything between Class [class name] and End Class is internal to the class object. All methods or variables declared in a class as Private have a "scope", or visibility, that does not extend outside the class. For example, you could declare the private variable "Object1" inside the class and use it to create an instance of the FileSystemObject. That variable, and the FSO instance, will not be visible outside of the class. The self-contained aspect of classes means that you can design a class as a custom object, choosing properties and methods to make visible by declaring them as Public, while the functionality behind those properties and methods is hidden inside the class.

   Since only the properties and methods of a class declared as Public are visible from outside the class, a class can be pasted into any number of scripts without having any effect on the operation of those scripts. It's like being able to paste the FileSystemObject into your script: Whether you use the object or not, it does not affect your script code because only the Public methods and properties are visible to the rest of the script. (Note, though, that public variables declared outside the class, in the same script, are visible from inside the class, so it's a good idea to use unique variable names inside script classes.)

   Many of the scripts available here use classes in order to neatly package functionality. You can use those classes by pasting them into your scripts and calling the public methods. You do not necessarily need to understand the code inside a class that you use, any more than you need to understand how the FileSystemObject works, although with VBScript classes you can also change the code and the public methods of the class.

   See the Class Demo and Class Block Demo samples (above) for more information about writing classes.

Back to Download List

Tutorial: Using HTAs (HTML Applications)
   A number of the downloads here are in the form of HTAs. Some of the JSWare utilities (Such as the MSI editor and XPFix tools) are also HTAs. This tutorial is here to provide a basic explanation and guid to using HTAs. HTAs are easy to use and there is not much to know, but there has been a great deal of misinformation concerning HTAs, unnecessarily making them seem exotic and abstruse.

   For all practical purposes, an HTA is just a webpage running in Internet Explorer, but with virtually no security restrictions. For some reason many people have got the idea that an HTA is a special kind of software program that is not running in a browser. That is not true. Microsoft's own webpage refers to HTAs as IE webpages. If you rename an HTML file with a ".hta" extension then it's an HTA. Simple as that.

A bit of history

   Internet Explorer has long been used to create interactive, highly functional, webpage utilities using HTML, CSS and script. Microsoft provided vast document object model functionality, as well as support for ActiveX. Unfortunately, that functionality has rendered IE all but unusable online. Internet Explorer is so closely tied into Windows, and provides so many ways to run executable code, that it is not safe to use on the Internet. With Internet Explorer 5 Microsoft began an effort to deal with that problem. They created the HTA -- which is little more than a method to turn off IE security restrictions -- while gradually increasing Internet Explorer security for normal webpages. That strategy allowed people to continue using IE to create script-based GUI programs by switching the file extensions from ."html" to ".hta".    Over time, Internet Explorer security has become an increasingly unworkable morass: not sufficient online and too restrictive offline. But HTAs continue to provide an easy, handy way to harness the extensive functionality of IE scripting.

The difference between HTA and HTML

   As noted above, if you rename an HTML file to HTA then you've got an HTA. That's all it takes. There are some minor details worth learning about, but in general there is nothing new that you have to learn. HTML, CSS and script work in an HTA just as they do in an HTML file loaded into Internet Explorer.

Security: The big difference with HTAs is security. The one and only security restriction is that an HTA must run locally. If you click a link to an HTA online with IE you will get a download prompt. Aside from that, all of your code should work. You can use FileSystemObject, "unsafe" ActiveX controls, etc.

Structure: Behind the scenes, an HTA file is actually loaded by a program named MSHTA.exe, rather than IEXPLORE.exe. MSHTA provides the parent window frame or "chrome". If you look at the window hierarchy under an instance of Internet Explorer vs an open HTA, you will see that all open webpages are displayed in a window with the class name "Internet Explorer_Server". That's the actual browser window. It's the essence of IE and of HTAs. But running the browser window through MSHTA provides a few extra options that do not exist with IE. An HTA window frame does not have the IE menu, toolbar and icons. Also, HTAs have a custom HTML tag that is read by MSHTA when the file is loaded. That tag is <HTA:APPLICATION>.

Using the <HTA:APPLICATION> tag

   <HTA:APPLICATION> is not required to turn a webpage into an HTA. Only the file extension change is required. But the <HTA:APPLICATION> tag is actually very useful. The tag goes in the HEAD tag, and according to Microsoft it is supposed to have a closing tag, like so: <HTA:APPLICATION> </HTA:APPLICATION>. That doesn't make sense, since the tag has no content, but it doesn't really matter, because it works fine either way - with or without the closing tag. The <HTA:APPLICATION> tag provides several attributes, which have corresponding script properties. (The properties have typical script property usage. Use an ID attribute for the tag like so: <HTA:APPLICATION ID="HTA"> </HTA:APPLICATION> in order to access the attributes at runtime. But note that the properties are generally read-only, so they're of little value.)

<HTA:APPLICATION> Attributes

The HTA attributes are listed below. Where there are a limited number of possible values, the default value is shown in bold.

ID: ID is a standard HTML attribute. It's mentioned only because it's needed to access the properties.
APPLICATIONNAME: This is an unusual attribute. An HTA title bar displays the content of the TITLE tag, just like a normal webpage. APPLICATIONNAME is used for something else: If a value is provided for APPLICATIONNAME then the class name of the HTA parent window will actually be changed to conform to that name. All windows in Windows have what is known as a class name, which indicates the type of window. Normally an HTA parent window has the class name HTML Application Host Window Class But if you use <HTA:APPLICATION APPLICATIONNAME="OkeyDokey"> then the parent window class name will become "OkeyDokey"! Windows uses this attribute with the SINGLEINSTANCE attribute. If SINGLEINSTANCE is set to "yes" the window class name helps to check for an already-running instance among the collection of open windows. There seems to be no other purpose to this attribute.
BORDER: thick, dialog, thin, none
BORDERSTYLE: normal, raised, sunken, complex (raised/sunken combo), static
CAPTION: yes, no. Despite the name, this property does not provide a title bar caption. (The TITLE attribute does that.) CAPTION controls whether the title bar is present at all.
CONTEXTMENU: yes, no. (Is the context menu functional?)
ICON: Path to 32x32 icon file to display on title bar.
INNERBORDER: yes, no. (Inner window border displayed? This property doesn't seem to work.)
MAXIMIZEBUTTON: yes, no. (Show max. button in control box on titlebar?)
MINIMIZEBUTTON: yes, no. (Show min. button in control box on titlebar?)
NAVIGABLE: no, yes. (Load links in same window? no, the default, is equivalent to TARGET="_blank", opening links in a new window.)
SCROLL: yes, no, auto. (Are scrollbars displayed?)
SCROLLFLAT: no, yes. (Are scrollbars shown flat? This property doesn't seem to work. Perhaps it requires XP styles.)
SELECTION: yes, no. (Can page content be selected for copying, etc.?)
SHOWINTASKBAR: yes, no.
SINGLEINSTANCE: no, yes
SYSMENU: yes, no. (Controls whether that useless little "system menu" appears when clicking on the program icon at far left of titlebar.)
VERSION: Optional version number.
WINDOWSTATE: normal, maximize, minimize

Getting App Path and Command Line in an HTA

   To get the parent folder path of the currently running HTA you can use a short function to clean up the window.location string, just as might be used in HTML:
Function GetHomePath() 
  Dim sHome, LPt
     GetHomePath = window.location
     GetHomePath = Replace(GetHomePath, "/", "\")
     LPt = InStrRev(GetHomePath, "\\")
        If LPt > 0 Then GetHomePath= Right(GetHomePath, (len(GetHomePath) - (LPt + 1)))
     GetHomePath= Replace(GetHomePath, "%20", " ")
     LPt = InStrRev(GetHomePath, "\")
     GetHomePath = Left(GetHomePath, LPt)  
  End Function
   With HTAs there is also a property of the <HTA:APPLICATION> element known as commandLine, which is accessed by using an ID attribute in the <HTA:APPLICATION> tag.
Ex.:
   <HTA:APPLICATION ID="HTA">
   s = HTA.commandLine

   Unfortunately, this leaves much to be desired. First, an HTA has no facility for drag-drop in its window. So while it's possible to get the path of a file dropped onto the HTA file in order to run it, there is no way to get the paths of files dropped onto the HTA window itself. And since an HTA is a GUI program, the startup commandline is of limited usefulness. In addition, commandLine returns a rather odd string. It does not contain the actual command line. Rather, it returns the HTA file path plus the command line! It's formatted as though it were a shell command line used to run the HTA. It's also confusing in that quotes are unpredictable. The HTA path seems to be sent in quotes even when there are no spaces in the path. Yet the path of a dropped file is only in quotes if the path has spaces. So, if you find that you have any use for this commandLine property at all then you'll need to clean it up after retrieving it:
<HTML><HEAD>
 <HTA:APPLICATION ID="HTA">
  <SCRIPT LANGUAGE="VBScript">
    Dim HTAPath, sCommand
    
      Sub window_onload()
        Dim s, Pt1, iQ, i2, Q2
        s = HTA.commandLine
        Q2 = Chr(34)
        iQ = 0
          For i2 = 1 to Len(s)
           Select Case Mid(s, i2, 1)
             Case " "
               If iQ Mod 2 = 0 Then 
                 HTAPath = Left(s, i2 - 1)
                 HTAPath = Trim(Replace(HTAPath, Q2, ""))
                   If Len(s) > i2 Then
                     sCommand = Right(s, Len(s) - i2)
                     sCommand = Trim(Replace(sCommand, Q2, ""))
                   End If  
                     Exit For
               End If    
             Case Q2
                iQ = iQ + 1
             Case Else
               '-
           End Select
         Next
      End Sub
   </SCRIPT>
  </HEAD>

IMPORTANT: A complex HTA may cause problems in IE whereby Windows insists on ending the execution of HTA script. See the next topic for explanation.

Back to Download List

Problems with Internet Explorer
The Wacky Script Timeout Bug: There is a bug with Internet Explorer, at least since IE 5.5: When a long operation runs in an HTA, you may see a message like the following:

"A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer may become unresponsive. Do you want to abort the script?"

   That message seems like a good idea. It provides a way to end a script that runs far longer than anticipated. But sometimes script in an HTA needs to run for several minutes, and once the timeout message appears it won't go away. Even if you dismiss the message, it just pops back up. The result is not an option to end a long script. Rather, one is forced to stop the script in order to end the inane message boxes!

   Microsoft does not seem to acknowledge this bug, but they do provide a webpage that offers help: http://support.microsoft.com/kb/175500
That page explains a Registry setting that can be used to eliminate the timeout warning messages. If you would like a pre-written script to make that setting, click here to download IETOFix.zip.

Back to Download List

Windows 32-bit vs 64-bit Issues
   All of the JSWare DLLs are 32-bit. A 32-bit library cannot run in a 64-bit process, and vice versa. What that means is that files here need particular treatment on a 64-bit system. The ActiveX EXEs run in their own process. They should work fine on Win64, but should not be put into the 64-bit System folder. All DLLs and OCX files here (which includes shell extensions such as BHOs, Explorer Bars, etc.) are in-process components. They can only be used by 32-bit programs. If you try to use use a 32-bit component in a script run by 64-bit WScript (Windows Script Host) the result will be similar to using a component without registering it. You will see a message saying "ActiveX Component Can't Create Object".

   To default to 32-bit WScript, you can change the path in the Registry key related to .VBS file. In most cases that will be HKEY_CLASSES_ROOT\vbsfile\. Under that key should be this key: HKEY_CLASSES_ROOT\vbsfile\shell\open\command\. The default value there will read something like C:\Windows\System32\WScript.exe "%1" %*. To use 32-bit WScript on 64-bit Windows, leave the value intact but change System32 to SysWOW64. That will cause 32-bit WScript.exe to handle .VBS files. (Confirm, first, that the 32-bit version is present on your system.)

Confusing System Folder Paths in 64-bit Windows:

   Unfortunately, Microsoft made a mess of folder and Registry paths in Win64, which can be confusing. When 32-bit Windows was developed, a new system folder was created, named System32. Common sense would say that Win64 should have another new folder, named System64. But that's not the case. The 64-bit folder on Win64 is System32! And the 32-bit folder has the ridiculous name of SysWOW64.

   JSWare components should be put into System32 on Win32, but must not be put into System32 on Win64, because a 32-bit process cannot see that folder. They should instead be put into SysWOW64, or just about any other folder.

Back to Download List

License Information

   This license supersedes any older license that may be included with scripts and components from JSWare.

  You use all script code and components from JSWare at your own risk.

  The components (compiled DLL and EXE files) may be used for personal or commercial purposes. No payment or attribution is required for either use. The components may be redistributed if they are required as support files for scripts or software that you have written.
   Also, the script code may be used freely, in part or as whole scripts, for any purpose, personal or commercial, without payment or attribution.

   I ask only that you not redistribute these scripts and components, except as required for your direct use. Instead, please direct others to obtain copies of JSWare scripts and components directly from www.jsware.net.

   Also, none of the code here may be redistributed under another license. If a work using code from JSWare is distributed with restrictions of any kind the code from JSWare must be kept exempt from those restrictions. This includes, but is not limited to, code sold for profit, code with usage restrictions and code distributed as so-called "Open Source" with redistribution restrictions.

   The software (or script or code) is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

Back to Download List