1, Wscript object

Description: provides access to the Windows script host object model root object.
details: the WScript object is the root object of the Windows script host object model hierarchy. It can be used in any script file without specific declarations. The
WScript object provides access to the following command line parameters, the name of the script file, the host file name, and the host version information. WScript objects can be used to create objects, connect objects, disconnect the objects, synchronize events, programmatically stop the execution of the script, and output the information to the default output device (Windows dialog or command console).

WScript object can also be used to set the script running mode (interaction mode or batch mode). As we said just now, the object wants us to provide tools through two kinds of its own characteristics. These two features are "attributes" and "methods", respectively.

two, attribute

1, Arguments attribute

Description: used to return Arguments objects (the object we will learn later, now only need to understand the line).
syntax: object.Arguments
parameter: object, WScript object

example: show the parameter

 Set Arg = WScript.Arguments = 0 Drag and drop them onto the VBS file, and then he will display the files you drag and drop one by one. (this only gives an example, uses the Arguments object, and we know later on) the 

2, the FullName attribute

Description: return the fully qualified path of the host executable file (CScript.exe or WScript.exe).
syntax: object.FullName
parameter: object, WScript object

example: show the path
MsgBox wscript.fullname
of the native Wscript in the default case will display the "C:WINDOWSsystem32wscript.exe"

and attribute description: set or determine the script mode .
syntax: object.Interactive
parameter: object, WScript object
Description: Interactive property returns a Boolean value.

has two modes of batch processing and interaction. Under the mode of interaction (default mode), the script provides users with interactive functions. Enable input and output to the host of Windows script. The script can display information in the dialog box and wait for the user to provide feedback. In batch mode, this type of user interaction is not supported, and all inputs and outputs to WSH are disabled. You can also use Windows script host command line switch / / I (for interactive) and / / B (for batch mode) to set script mode.

example: show the script mode of the native
MsgBox WScript.Interactive

4, Name attribute
Description: return the name of the WScript object (host executable file).
syntax: object.Name
parameter: object, WScript object
MsgBox WScript.name

5, Path attribute

Description: return the path name containing the host executable file Like the
MsgBox WScript.Path
if your wscript.exe is "C: WINDOWS system32 wscript.exe" then this property will display the "C: WINDOWS system32" Description: return the full path of the current run script.
syntax: object.ScriptFullName
parameter: object, WScript object
example: show the complete path of this VBS
MsgBox WScript.ScriptFullName

magic bar, this VBS knows his own name.

7 and ScriptName attribute

Description: returns the file name of the current run script.
syntax: object.ScriptName
parameter: object, WScript object
Description: just now we know how to use ScriptFullName to get the full path of the VBS file itself, what do you want to do with the name of the file? Look at the examples.
example: show the name of this VBS file
MsgBox WScript.ScriptName
? Did you see?

8 and Version attribute

Description: returns the version of Windows script host.
syntax: object.Version
parameter: object, WScript object
example: display the native script host version
MsgBox WScript.version

three, method

1, CreateObject method description: create an object syntax: Br> explains: appName is required, Variant (string). The name of the application that provides the object.
objectType required; Variant (string). The type or class of the object to be created.
servername is optional; Variant (String). The name of the network server to create objects on it.
explains: to create a ActiveX object, you only need to assign an object returned by CreateObject to an object variable: a reference to the
, Set ExcelSheet = CreateObject ("Excel.Sheet") '.
each supporting automation application provides at least one object type.

, for example, a word processing application may provide Application objects, Document objects, and Toolbar objects. To create a ActiveX object, you only need to assign an object returned by CreateObject to an object variable:

 Dim ExcelSheet As Object'declares an object variable to store the object Set ExcelSheet = CreateObject ("Excel.Sheet") ExcelSheet.Cells (1, 1).Value = "This is column A, row 1" 'write some text ExcelSheet.SaveAs "C: TEST.xls" in the first unit of the table. Save the table to the C:test.xls directory ExcelSheet.Application.Quit' using the application object object. Set ExcelSheet = Nothing'releases the object variable, 

, which will start the application to create the object, in this case the creation of a Microsoft Excel electronic data table. Once the object is created, you can use the custom object variable to reference the object in the code. In the following example, you can use the object variable ExcelSheet to access the properties and methods of the new object, as well as other objects that access the Microsoft Excel, including the application object and the cell collection. The

2, the GetObject method

describes: retrieving an Automation object from a file, or retrieving the object
syntax specified by the strProgID parameter: object.GetObject (strPathname [, strProgID], [strPrefix]) parameters: the necessary option. WScript object.
option, strPathname. Contains the complete path and name of the object to be acquired.
is strProgID option. A string representing the object's program identifier (ProgID).
is strPrefix option. If the parameter strPrefix is specified, the Windows script host will connect the output interface of the object to the script file after the object is created. When triggering an event in an object, the Windows script host will call a subroutine whose name includes strPrefix and the name of the event.

, for example, if strPrefix is "MYOBJ_", the event generated by the object is "OnBegin,", then the Windows script host will call the "MYOBJ_OnBegin" subroutine in the script.

explains: if there is an instance of an object at present, or if you want to create an object using a file that has already been loaded, you can use the GetObject method. If there are no instances at the moment and do not want to start objects from the loaded files, use the CreateObject method.

, if an object registers itself as a single instance object (for example, the Word.Basic object in Microsoft Word 7), can only create an instance of the object no matter how many times the CreateObject is executed. In addition, for a single instance object, GetObject always returns the same instance if it is called with zero length string syntax (""), and if the path parameter is omitted, the error will be caused. Using GetObject, you can not get references to Microsoft Visual Basic (R) classes created by Visual Basic 4 and previous versions.

GetObject is applicable to all COM classes and is not restricted by the language used to create objects.

example: when executing the following code, the application associated with the specified strPathname is activated, and the object in the specified file is activated. If strPathname is a zero length string (""), GetObject will return a new object instance of the specified type. If the strPathname parameter is completely omitted, GetObject will return the current active object of the specified type. If there is no object of the specified type, an error will occur.

 Dim MyObject As Object Set MyObject = GetObject ("C:CADSCHEMA.CAD") MyApp = MyObject.Application

limitations some applications allow certain parts of a file to be activated. If you want to do this, you need to add an exclamation mark after the file name, and then identify the part you want to be activated in a file with a string. For information about how to create this string, see the documentation about the application that creates the object.

, for example, in a drawing application, a graph stored in a file may contain multiple layers. You can use the following code to activate a layer in the drawing file called schema.cad:

Set LayerObject = GetObject ("C:CADSCHEMA.CAD! Layer3")
if no class of objects is specified, COM will determine the application and the object to be activated based on the file name provided. However, some files may support multiple object classes. For example, a drawing may support three different types of objects: an application object, a drawing object, and a toolbar object, both of which are part of the same file.

in the next example, FIGMENT is the name of a drawing application, and DRAWING is one of the object types it supports.

Dim MyObject As Object
syntax: object.Quit [intErrorCode]
explains: object must. WScript object.
is intErrorCode option. If this parameter is included, WScript will return it as the process termination code. If intErrorCode is omitted, WScript returns zero (0) as the process termination code.
exits and returns the error code 1:


4, Sleep method

Description: make the script process inactive within the specified milliseconds, and then continue execution.
syntax: object

This concludes the body part