CreateObject / wscript.CreateObject

Create a Windows Scripting Host (WSH) automation object / run an external command.

      Set objObject = CreateObject(ServerName.typeName, [Location])

   ServerName   The name of the application
   typeName     Type or class of object to create
   Location     The name of the server. (creates the object on a remote server via DCOM)

      Set objObject = WScript.CreateObject(strProgID[, strPrefix])

   strProgID    The programmatic identifier of the object to create. String value.
   strPrefix    String value indicating the function prefix.
                Create a local object and hook up its event handlers

Objects created with the wscript.CreateObject method using the strPrefix argument are connected objects.
These are useful when you want to sync an object's events.

CreateObject is a wscript method.


Run a cmd command from vbs

Set objShell = Wscript.CreateObject("Wscript.Shell")"%comspec% /c ipconfig /release")

Run a cmd batch file from vbs

Set objShell = Wscript.CreateObject("Wscript.Shell")"%comspec% /c mybatchfile.cmd")

Create a WshController object to run scripts on a remote machine:

strServer = "machine_name"
strScript = "script_name.vbs"
Set objWshController = WScript.CreateObject("WshController")
Set objRemoteScript = objWshController.CreateScript(strScript, strServer)

For the above to work, enable DCOM , then enable WshRemote in the registry:

HKLM\Software\Microsoft\Windows Script Host
String value: Remote

Set Remote to "1" to enable WshRemote and "0" to disable.

Create a WshNetwork object (for mapping to a network share)
WshNetwork = WScript.CreateObject("WScript.Network")

Echo the script mode.
WScript.Echo (WScript.Interactive)

“ understanding of Visual Basic would be advantageous although not to a programming level.” ~ Job advert on


cscript - Run a VBScript .vbs file
.GetObject - Get an Automation object
.ConnectObject - Connect to a COM object
.DisconnectObject - Disconnect from a COM object
.Exec - Run a command
The difference between WScript.CreateObject and CreateObject - Eric Lippert
psExec - Run commands remotely
Equivalent in Powershell - New-Object

Copyright © 1999-2017
Some rights reserved