.CreateObject - VBScript


Overview

The .CreateObject command in VB Script is used to create an instance of an ActiveX object. It is primarily used for interacting with external applications, libraries, or system components that provide specific functionality.

Syntax

.CreateObject(progID | classID)

Parameters:

  • progID: The ProgID (Programmatic Identifier) of the object to be created.
  • classID: The class identifier of the object to be created.

Options/Flags

None

Examples

Simple Usage:

Set objExcel = .CreateObject("Excel.Application")

Complex Usage:

Set objShell = .CreateObject("Shell.Application")
strOutput = objShell.Exec("ipconfig /all")

Common Issues

Object Not Found: Ensure that the specified ProgID or classID is correct and registered on the system.

Permission Denied: Check if the script is running with sufficient privileges to create the object.

Timeout: Set a timeout for object creation to prevent indefinite waiting.

Integration

.CreateObject can be combined with other VB Script commands to automate tasks. For example:

.CreateObject("Scripting.FileSystemObject").CreateFolder("C:\New Folder")
  • .GetObject: Obtains an existing instance of an ActiveX object.
  • .GetActiveObject: Retrieves the active instance of an ActiveX object.
  • .Exec: Executes a system command or program.