Early Bound Vs Late Bound (Binding)

What is Binding

Before we dive into ‘Early’ and ‘Late’ stuff, let us discover, what the ‘Binding’ itself means?
In simple terms, the ‘Binding’ refers to the way a script or an application accesses a COM Automation object. This is manifested as the association of entities such as data, program, procedures etc. with identifiers.

It is done when the application is compiled and all functions called in code must be bound before the code can be executed. In the premise of VBScripting, when a script or application attempts to create an instance of a COM object, it inherently verifies the existence of the object in the relevant or specified namespace besides this the object’s methods and properties (called in the script) are also verified. This entire process of locating and verification while creating an instance of COM Object is called ‘Binding’.

Binding with VBScript

Here are some typical examples of binding –

Set MyObject = CreateObject ("Word.Application") 
Set MyObject = GetObject ("winmgmts:") 
Set MyObject = WScript.CreateObject ("Scripting.FileSystemObject")

In general, there are two methods to bind to a COM object using VBScript syntax as specified below (other variations exist as well depending upon the specific needs or style) –

  • CreateObject (“[Component or Server or Moniker][.][Object or typename]”)
  • GetObject (“[Component or Server or Moniker][.][Object or typename]”)

However, if you wish to use purely WSH scripts, then the syntax would slightly change to accommodate the prefix – ‘WScript’ and as in ‘WScript.CreateObject’ and ‘WScript.GetObject’.

What is the difference between the above two methods, i.e. CreateObject and GetObject again requires a good explanation which may be out of scope of this post. But in short – ‘You should use GetObject while using monikers and if the object to which you are binding exists outside the â€˜File System’ namespace examples would be WMI and ADSI. For all other purposes CreateObject should do fine

Coming back to Early and Late terms, the ‘COM’ support two types of binding –

COM Binding Types Explained

1Early Binding :With this type of binding the ‘COM Object’, its methods and properties are all checked when the script or program is compiled. This has some obvious advantages. Firstly any problems with ‘COM Object’ binding if exist makes the compilation to fail and hence results in the early discovery of related issues. Secondly, this provides the advantage of early access to object model and library (COM) and hence the related information is loaded itself into the compilation or the program. Lastly, as obvious scripts or programs supporting ‘Early Bindinding’ are relatively faster.

2Late Binding : Since VBScript is a not a compiled language, natively it supports only ‘Late Binding’. Hence unlike the ‘Early Binding’, in case of VBScript the binding does not occur until the program is actually executed. In this scenario the program usually performs frequent registry or namespace lookups upon execution to access the information about the ‘COM Objects’, consequently any issues with the COM information are not discovered until the actual execution of the script/program.

Tushar Sharma
Tushar Sharmahttps://www.automationdojos.com
Hi! This is Tushar, the author of 'Automation Dojos'. A passionate IT professional with a big appetite for learning, I enjoy technical content creation and curation. Hope you are having a good time! Don't forget to subscribe and stay in touch. Wishing you happy learning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

RELATED POSTS

How To Write Windows Environment Variables With VBScript

This is in continuation to the last post where we saw how to read windows environment variables using VBScript. As mentioned in the last...

How To Auto-launch VBscript with Elevated Privileges

For cases when you need to execute a VBS script (*.vbs file) as admin with elevated privileges you can try the following snippet. This...

What is In-Proc and Out-Proc (COM) ?

The terms 'In-Proc' and 'Out-Proc' are to describe the kind of implementation of COM Servers. Before we begin, for those who are not quite...

Â

RECENT 'HOW-TO'

How To Install Oh-My-Posh On Windows PowerShell

Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable. It does not...

SIMILAR ON CODEX

FEATURED PROJECTS

SEPA Bulk File Generator and Validator

ADjo LABS PROJECT: SEPA Bulk File Generator and Validator. Supported File Types PAIN008, PAIN001, PACS003 and PACS008. Tested for supporting PAIN.008.001.001 and PAIN.008.001.002 (version 1&2). The XML...

MORE IN THIS CATEGORY

Introduction to Apache Maven

1. What is Maven When you write a software application, there are many steps in it like adding the necessary JAR files, compiling the source...

Convert String to Date Using SimpleDateFormat Class

Sometimes, you may need to convert a String to a java.util.Date object. For this, you need to use the SimpleDateFormat class. You need to...

Java Tutorial #5 – Loop Statements

Iteration statements are used to repeat a particular block of code until a certain condition is true. In this article, we will be taking...

CHECKOUT TUTORIALS

VBS Part 2 – Fundamentals and Concepts

Having gone through the Introductory part, it is time to look at some crucial fundamentals and concepts. This article is to refresh some of...
- Advertisement -spot_img