A good VBS-JSCRIPT GETOBJECT understanding

Source: Internet
Author: User

Two years ago, when I was writing ASPSHELL, I never understood why.
GetObject ("WinNT: //.") can obtain important information about the local system.
At that time, MSDN had such a resolution.
-----------
Windows Script Host
GetObject Method
See
WScript object | CreateObject method | DisconnectObject Method
Use the specified ProgID to retrieve an existing object or create a new object from the file.
Object. GetObject (strPathname [, strProgID], [strPrefix])
Parameters
Object
WScript object.
StrPathname
The fully qualified path name of the file that contains objects retained to the disk.
StrProgID
Optional. The program ID of the object ).
StrPrefix
Optional. Used when you want to synchronize the event of the object. If you provide the strPrefix parameter, WSH connects the output interface of the object to the script file after creating the object.
Description
If the object instance is stored in the memory or you want to create an object from a file, use the GetObject method. If the memory does not have the current instance and you do not want to create an object from the file, use the CreateObject method. The GetObject method can be used for all COM classes, regardless of the language used to create the object. If you provide the strPrefix parameter, WSH connects the output interface of the object to the script file after creating the object. When an object triggers an event, WSH will call the child routine with a strPrefix at the beginning of the event name. For example, if the strPrefix is MYOBJ _ and the event name raised by the object is OnBegin, WSH calls the MYOBJ_OnBegin subroutine in the script.
If an object is registered as a single instance object, only one instance of the object is created (no matter how many times you run GetObject ). The instance returned by the GetObject method is always the same as the instance called using the zero-length string syntax (""). If no path parameter is provided, an error occurs. The GetObject method cannot be used to obtain references to Microsoft Visual Basic classes created with Visual Basic 4.0 or earlier.
Example
The following VBScript code starts 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 the file. Add an exclamation point (!) at the end of the file name (!), And then append a string that identifies the part of the file to be activated. For example, a drawing stored in a file may have multiple layers in a drawing application. The following code activates a layer in the drawing file named SCHEMA. CAD:
Set LayerObject = GetObject ("C: \ CAD \ SCHEMA. CAD! Layer3 ")
If the strProgID of the object is not specified, COM determines the application to be started from the file name. Some files support multiple object classes. For example, a drawing may 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 starts from the SAMPLE. DRW file and opens the DRAWING Object.
Dim MyObject As Object
Set MyObject = GetObject ("C: \ DRAWINGS \ SAMPLE. DRW", "FIGMENT. DRAWING ")
See
WScript object | CreateObject method | DisconnectObject Method
---------------
But I haven't understood it yet ~~
Today, N years later ~~ I suddenly read an article ~~~ Finally understood
In fact, GetObject retrieves information from a file or object to obtain its operation.
For example
GetObject ("WinNT: //.") is the system object ~
If your system has an EXCEL file of OFFICE, we can get the object in this way.
Set xls = GetObject ("d: \ 1.xls"," Excel. Application ") 'the first parameter is the xls file path. The second parameter is the object type.
It can also be automatically recognized by him.
Set xls = GetObject ("d: \ 1.xls ")

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.