◎ WMI-Definition of resolution classes

Source: Internet
Author: User
As we mentioned in the previous article, in WMI, classes are used to abstract and define and manage managed resources. So what is a class?
The definition of a class can be found in many object-oriented computer textbooks. My understanding is that a class contains a group of independent functional modules, which are composed of data and functions, data is called a class attribute, and the completed function is called a class method. In my opinion, the advantages of a class are that the class can be completely designed by James and can be used directly by James. When using the class, James does not need to know how to design and implement the class, you only need to know what functions this class can implement and what methods and attributes this class contains. More importantly, classes can also be inherited, just as if the father died and the son inherited all his father's assets. If we find that a class A has completed most of the functions we need, we re-design a new class to complete all our functions, which is time-consuming and laborious. According to the characteristics that can be inherited by the class, we only need to declare that a class inherits Class, then add new data elements as needed and expand the existing functional modules. I believe the work will be much simpler. I have seen many books talking about code reuse. I am not a programmer and do not know how code reuse is implemented. But I believe classes should play an important role in it.
In the Microsoft tutorial, the class is described in detail in terms of the function and inheritance relationship. I will not go into details, just make a summary:
  

If WMI is required to host any resource, at least two files are required: the provider and the MOF file. The provider is a middleware that responds to WMI requests by calling the local API for hosting resources.
Each hardware and software resource managed by WMI has a class to define. Conversely, a CIM class is a template for WMI-managed resources, and all instances of resources use this template. These templates are composed of attributes, methods, and delimiters. These attributes, methods, and delimiters are defined in the MOF file. Methods and attributes are frequently encountered. What is a qualifier? The qualifier is an additional modifier of the class, attribute, or method type. The class is static, abstract, or associated, the attribute is read-only, writable, And the return parameter of the method, all are defined in it. How do we know the delimiters of a class? The following code helps us easily obtain the attributes, methods, and qualifiers of a class.

Code:
Strcomputer = "."
Strnamespace = "root/cimv2"
Strclass = inputbox ("Enter the class you want to query ")

Set objclass = GetObject ("winmgmts: //" & strcomputer &_
"/" & Strnamespace & ":" & strclass)

The limitations of wscript. Echo strclass & "are as follows :"
Wscript. Echo "------------------------------"
I = 1
For each objclassqualifier in objclass. qualifiers _
If vartype (objclassqualifier. Value) = (vbvariant + vbarray) then' constant vbvariant is returned only with vbarray to indicate that the vartype function parameter is an array of the variant type.
Strqualifier = I & "." & objclassqualifier. Name & "= "&_
Join (objclassqualifier. value ,",")
Else
Strqualifier = I & "." & objclassqualifier. Name & "= "&_
Objclassqualifier. Value
End if
Wscript. Echo strqualifier
Strqualifier = ""
I = I + 1
Next

Wscript. Echo
Wscript. Echo strclass & "class attributes and attribute limitation information"
Wscript. Echo "-------------------------------------------------"
I = 1: j = 1
For each objclassproperty in objclass. properties _
Wscript. Echo I & "." & objclassproperty. Name
For each objpropertyqualifier in objclassproperty. qualifiers _
If vartype (objpropertyqualifier. Value) = (vbvariant + vbarray) then
Strqualifier = I & "." & J &"."&_
Objpropertyqualifier. Name & "= "&_
Join (objpropertyqualifier. value ,",")
Else
Strqualifier = I & "." & J &"."&_
Objpropertyqualifier. Name & "= "&_
Objpropertyqualifier. Value
End if
Wscript. Echo strqualifier
Strqualifier = ""
J = J + 1
Next
Wscript. Echo
I = I + 1: j = 1
Next

Wscript. Echo
Wscript. Echo strclass & "class method and method limitation information"
Wscript. Echo "-------------------------------------------------"
I = 1: j = 1
For each objclassmethod in objclass. Methods _
Wscript. Echo I & "." & objclassmethod. Name
For each objmethodqualifier in objclassmethod. qualifiers _
If vartype (objmethodqualifier. Value) = (vbvariant + vbarray) then
Strqualifier = I & "." & J &"."&_
Objmethodqualifier. Name & "= "&_
Join (objmethodqualifier. value ,",")
Else
Strqualifier = I & "." & J &"."&_
Objmethodqualifier. Name & "= "&_
Objmethodqualifier. Value
End if
Wscript. Echo strqualifier
Strqualifier = ""
J = J + 1
Next
Wscript. Echo
I = I + 1: j = 1
Next
If we execute the above Code to find the qualifier of the win32_service class, the following information is generally obtained:
The limitations of the win32_service class are as follows:
------------------------------
1. Dynamic = true
2. locale = 1033
3. provider = cimwin32
4. supportsupdate = true
5. UUID = {8502c4d9-5fbb-11d2-aac1-006008c78bc7}

Attributes and attribute limitation information of the win32_service class
------------------------------------------------------
1. acceptpause
1.1. cimtype = Boolean
1.3. Read = true
......
Method and method limitation information of the win32_service class
-------------------------------------------------
1. startservice
1.1. mappingstrings = WIN32API | service functions | startservice
1.2. Override = startservice
1.3. valuemap =, 24 ,..
......
There are a lot of returned information. I omitted most of the information and kept only some of the typical information to illustrate how to read the limited information of the class.
The first part of the returned information indicates the limitation information for this class:
1. Dynamic = true abstract -- abstract class, dynamic -- Dynamic class, Association -- Association class, indicating that win32_service class is dynamic class.
2. locale = 1033 indicates the region setting or local code. It is a set of user preferred information related to the user's language, country/region, and cultural traditions, such: the keyboard layout, the sort order of letters, and the format of date, time, number, currency, etc.
3. provider = cimwin32 provider represents the class provider, indicating that the win32_service class is provided by cimwin32.dll.
4. supportsupdate = true indicates whether the class supports instance modification.
5. UUID = {8502c4d9-5fbb-11d2-aac1-006008c78bc7} represents a globally unique identifier on the local computer.
  
The second part of the returned information represents the attribute qualifier of the class.
1. acceptpause
The first line indicates that the property name of the retrieved class is acceptpause.
1.1. cimtype = Boolean cimtype indicates the Data Type of the attribute. This indicates that this attribute is boolean.
1.3. Read = true read indicates that the attribute is readable, while write indicates whether the attribute value can be modified. What does it mean if the attribute does not define the write qualifier? It indicates that the attribute of the Instance obtained from this class cannot be rewritten, that is, the attribute cannot be assigned a value. This actually solves a problem that has been confusing me for a long time. Why did I submit the modification using the put _ method after assigning values to attributes of many classes, but in fact nothing has changed. In addition, the key qualifier specifies that this attribute is the key of the class, which is used to identify the unique instance that hosts resources in the same resource set.
  
The third part of the returned information represents the class method and method qualifier. Now we can use not much, will not introduce, interested friends can refer to: http://msdn2.microsoft.com/en-us/library/aa393650.aspx
It should be noted that, not in every class definition, attribute, and method definition, all the delimiters will appear, and only some of them may appear.
Of course, we can also read the class definition and class description of the entire managed resource from the system32/WBEM/cimwin32.mof and system32/WBEM/cimwin32.mfl files, it also describes the attributes, methods, and delimiters of each class. It contains a lot of information and more class delimiters, which are difficult to read. Combine the code in the above example with the Object Browser contained in vbsedit to obtain the vast majority of information we need.

 

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.