All Objects
OBJECT: WScript
The
WScript
object is directly available to all scripts being executed by wscript or cscript and represents the currently running instance of the scripting host executable (wscript or cscript). The
WScript
object cannot be instantiated directly using CreateObject, however scripts running under WSH can obtain a reference to it via the
Application
property.
Through the
WScript
object one can gain access to WSH version information, the paths to the host executable and the script currently being executed, any arguments passed to the script, and the standard input, output and error streams. In addition, the
WScript
object can be used to instantiate, obtain references to, and bind to COM components. Methods and properties are also available to alter the script timeout values, and to cause the script to sleep for a specified period of time.
PROPERTIES
Application Property
The
Application
property is read only and returns a reference to the current WScript instance.
Syntax:
WScript.
Application
BuildVersion Property
The
BuildVersion
property is read only and returns a Long value which is the build version number of the host executable file (cscript or wscript).
Syntax:
WScript.
BuildVersion
FullName Property
The
FullName
property returns the full path to the host executable file (cscript or wscript). This property is read only.
Syntax:
WScript.
FullName
Interactive Property
The
Interactive
property returns a Boolean that indicates whether or not the host executable file (cscript or wscript) was invoked in interactive mode. This property is read/write and can be used to change the mode of the currently executing script at runtime. When this property is False, interactive commands such as Echo, MsgBox and InputBox have no effect. The
WshShell.Popup
method, and the use of
StdErr
,
StdIn
and
StdOut
are, however, unaffected by the setting of this property.
Syntax:
WScript.
Interactive
[ = True|False]
Name Property
The
Name
property is read only and returns the name of the WScript object (usually "Windows Script Host"). This is the default property of the WScript object.
Syntax:
WScript[.
Name]
Path Property
The
Path
property is read only and returns the full path to the directory containing the host executable file (wscript or cscript).
Syntax:
WScript.
Path
ScriptFullName Property
The
ScriptFullName
property is read only and returns the full path to the script currently being executed.
Syntax:
WScript.
ScriptFullName
ScriptName Property
The
ScriptName
property is read only and returns the filename of the script currently being executed.
Syntax:
WScript.
ScriptName
StdErr Property
The
StdErr
property returns a write-only TextStream object that outputs text to the Standard Error stream. This property is read only and can only be used when cscript is the host executable.
Syntax:
WScript.
StdErr
StdIn Property
The
StdIn
property returns a read-only TextStream object that reads text from the Standard Input stream. This property is read only and can only be used when cscript is the host executable.
Syntax:
WScript.
StdIn
StdOut Property
The
StdOut
property returns a write-only TextStream object that outputs text to the Standard Output stream. This property is read only and can only be used when cscript is the host executable.
Syntax:
WScript.
StdOut
Timeout Property
The
Timeout
property is used to set or get the timeout period (in seconds) for the currently executing script. The script will automatically be terminated after the number of seconds specified by this property, which is of type Long.
Syntax:
WScript.
Timeout
[ = lngTimeout]
Version Property
The
Version
property
is read only
and returns a string that is the version number of the host executable.
Syntax:
WScript.
Version
COLLECTION PROPERTIES
Arguments Collection Property
The
Arguments
collection property is read only and returns the collection of arguments supplied when invoking the current script. The argument list does not include the name of the host executable file (cscript or wscript), or the name of the script being invoked.
Syntax:
WScript.
Arguments
METHODS
ConnectObject Method
The
ConnectObject
method binds the events of an object to event handlers (sinks) in the currently executing script.
Syntax:
WScript.
ConnectObject
objObject, strSubPrefix
CreateObject Method
The
CreateObject
method creates an instance of a COM component with a specified ProgID and, optionally, registers the current script as a handler for events generated by the newly created object.
Syntax:
WScript.
CreateObject
(strProgID, [strSubPrefix])
DisconnectObject Method
The
DisconnectObject
method disconnects any event-handling connection between the currently executing script and the specified object. If a connection with the specified object was not previously established with a call to ConnectObject, CreateObject or GetObject, then this method does nothing.
Syntax:
WScript.
DisconnectObject
objObject
Echo Method
The
Echo
method concatenates its arguments into a space-separated string and displays this string in a Dialog Box (if invoked under wscript), or on the standard output stream (if invoked under cscript). Under cscript, a newline character is appended to the output. This method has no effect if the
WScript.Interactive
property is False.
Syntax:
WScript.
Echo
[vntArg1] [,vntArg2] [,vntArg3] ...
GetObject Method
The
GetObject
method loads the specified file into the associated application and returns a reference to the instance of the application object. If an application object of the appropriate type already exists, the specified file will be loaded into the existing instance, otherwise a new instance will be created. If the specified file can be handled by multiple applications, the ProgID of the desired application can be specified. If an empty string is specified for the filename, a ProgID must be specified, and this method will behave the same as a call to
CreateObject
. The
GetObject
method can also be used to register the current script as an event-handler for the returned object.
Syntax:
WScript.
GetObject
(strPathName [,strProgID] [,strSubPrefix])
Quit Method
The
Quit
method causes the current script to terminate and return the specified exit code.
Syntax:
WScript.
Quit
[lngExitCode]
Sleep Method
The
Sleep
method causes execution of the current script to be suspended for the specified number of milliseconds.
Syntax:
WScript.
Sleep
lngTime
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information