A good piece of vbs-jscript GetObject understanding _vbs
Source: Internet
Author: User
2 years ago, when I was writing Aspshell, I didn't understand why.
GetObject ("winnt://.") can get some important information about the local system
When MSDN was such an analytic
-----------
Windows Script Host
GetObject method
Please see
WScript Objects | CreateObject method | Disconnectobject method
Retrieves an existing object or creates a new object from a file, using the specified ProgID.
Object. GetObject (Strpathname [, Strprogid], [Strprefix])
Parameters
Object
WScript object.
Strpathname
The fully qualified path name of the file that contains the object that is persisted to the disk.
Strprogid
Optional. An object's program identifier (ProgID).
Strprefix
Optional. Used when you want to synchronize an event for an object. If you supply the Strprefix parameter, WSH will connect the output interface of the object to the script file after the object is created.
Description
If an instance of an object is stored in memory, or if you want to create an object from a file, use the GetObject method. If there is no current instance in memory and you do not want to create an object from a file, use the CreateObject method. The GetObject method is available for all COM classes, regardless of the language used to create the object. If you supply the Strprefix parameter, WSH will connect the output interface of the object to the script file after the object is created. When an object raises an event, WSH calls the subroutine that attaches the strprefix at the beginning of the event name. For example, if Strprefix is Myobj_ and the object throws an event named Onbegin, WSH the Myobj_onbegin subroutine in the call script.
If an object is registered as a Single-instance object, only one instance of the object is created (regardless of how many times you have performed GetObject). The instance returned by the GetObject method is always the same as an instance that is called with a 0-length string syntax (""), and an error occurs if the path parameter is not supplied. The GetObject method cannot be used to obtain a reference to a Microsoft Visual Basic class that was created with Visual Basic 4.0 or later.
Example
The following VBScript code launches the application associated with the specified file (strpathname):
Dim MyObject as Object
Set MyObject = GetObject ("C:\CAD\SCHEMA. CAD ")
MYAPP = Myobject.application
Some applications allow you to activate part of a file. To do this, add an exclamation point (!) at the end of the file name and append a string to the identity file that you want to activate. For example, in a drawing application, the drawings stored in a file may have multiple layers. The following code activates the name SCHEMA. One of the layers in a CAD drawing file:
Set layerobject = GetObject ("C:\CAD\SCHEMA. Cad! Layer3 ")
If the object's Class (Strprogid) is not specified, COM determines which application to start from the file name. Some files can support multiple object classes. For example, a drawing might support three different types of objects: application objects, drawing objects, and toolbar objects. All of these may be in the same file.
In the following VBScript code, the drawing application figment from SAMPLE. DRW the file to start and open the DRAWING object.
Dim MyObject as Object
Set MyObject = GetObject ("C:\DRAWINGS\SAMPLE. DRW "," figment. DRAWING ")
Please see
WScript Objects | CreateObject method | Disconnectobject method
---------------
But did not understand after reading ~ ~
N years after the Today ~ ~ Suddenly read an article ~ ~ Finally understand the
In fact, GetObject is getting information from a file or object to get its operation.
For example
GetObject ("winnt://.") This is the System object ~
And if you have Office EXCEL installed in your system, then we can get the object
Set xls = GetObject ("D:\1.xls", "Excel.Application") ' first parameter is the file path of XLS the 2nd parameter is the type of the object
You can also let him automatically identify
Set xls = GetObject ("D:\1.xls")
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.