CreateObject

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

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

Key:

   ServerName   The name of the application

   typeName     Type or class of object to create

   Location     The name of the server. 

Examples

Run a cmd command from vbs

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

Run a cmd batch file from vbs

Set objShell = Wscript.CreateObject("Wscript.Shell")
objShell.run("%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)
objRemoteScript.Execute

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)

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

Related:

cscript - Run a VBScript .vbs file
.Exec - Run a command
.GetObject - Get an Automation object
.DisconnectObject
psExec - Run commands remotely
Equivalent in Powershell - New-Object


© Copyright SS64.com 1999-2013
Some rights reserved