A concise tutorial on Wmi_vbs script Programming supplementary reading 1th/2 page _vbs

Source: Internet
Author: User
Tags aliases switches xsl xsl file advantage

Today, my swamp is going to introduce you to a friend, Microsoft Windows Management Instrumentation (WMI). The Chinese name is called Windows Management specification. Starting with Windows 2000, WMI (the Windows Management Specification) is built into the operating system and is an important part of Windows System Management. So it's easy to see because we should at least be a Windows 2000 user. Below I will detail each of its details, so that you never know it to like it.
What can WMI do?
Not only can WMI get the computer data it wants, but it can also be used for remote control. Remote control computer is something that everyone likes. Many remote monitoring control class software typically runs a server-side daemon on a remote computer, runs a client-side control program on the local computer, and implements remote control of the computer through the collusion of these two programs. The disadvantage of this approach is very obvious, when the server program is turned off, this remote monitoring can not be achieved, because there is no inside. While the remote monitoring and control implemented by WMI does not require anything else on the server, the system defaults to the WMI service. Specifically, WMI has the following capabilities:
1. Obtain hardware software information for local and remote computers.
2. Monitor health conditions such as software and services for local and remote computers.
3. Controls the running of software and services for local and remote computers.
4. Advanced applications.

How do I access WMI?
When we know some of WMI's capabilities, we've been wondering how to get to know him and use him. There are many ways to take advantage of WMI, which is simply three:
1. Through Microsoft to provide us with the various tools to achieve common query and operation. This includes WMIC at the command prompt, and the WMI TOOL Microsoft has provided to us, and you can download it for free on Microsoft's website, which I can also offer for free.
2. Use your own scripting to achieve more flexible operations. To be truly flexible and practical, familiarity with WSH scripts is a must, of course, if you are not familiar with the relationship, I will give you a detailed explanation later.
3. To access and manipulate it by writing our own program. Any language is fine. If used. NET class procedure to be simpler, if uses the VC and so on to be more complicated, at least I think so.
4. Another way to access it is to go to one of its nests. Everything in the C:\WINDOWS\SYSTEM32\WBEM directory is closely related to it, there are logs and various tools, in which you can find a lot of answers. But these things are generally not suitable for our novice to play, it is a bit scary.

Our mission for today?
Today we have five tasks:
Task one: Use WMIC to list all processes on a remote computer.
Task two: Use WMIC to close the local process.
Task three: Keep the process information of the remote host in a Web page through WMIC
Task four: Monitor each other's progress in real time with scripts
Task five: Use script to open sharing to each other
To view and monitor the process, but also to kill the process, and finally to give each other a share, our friend quickly to do the bad things. Understand our mission and we'll be on the road. This time we will mainly use WMIC and script to achieve our task, so we will be divided into two major parts to explain. In the five task of the actual combat we will be more in-depth understanding of it, no foundation is not related, I will try to explain all the so-called basis, so that everyone can easily communicate with this friend.

The first part: using WMIC to understand WMI
WMIC is the abbreviation for Windows Management Instrumentation commandline, and WMIC extends WMI, providing support for system management from command-line interfaces and batch command scripts. Provides a powerful, user-friendly command-line interface for the WMI namespace. With the wmic,wmi on the obvious approachable.
Executing the WMIC command launches the WMIC command-line environment. When the WMIC command is executed for the first time, Windows first installs WMIC and then displays the command line prompt for WMIC. At the WMIC command-line prompt, the commands are executed interactively. If you don't know how to interact with it, please hit a "/?" and read through all the instructions, and you'll see. WMIC can also run in a non-interactive mode. Non-interactive mode is useful if you want to perform a single-step task, or run a series of WMIC commands in a batch command. To use non-interactive mode, simply start WMIC on the same command line and enter the command you want to execute.

1. Task one: Use WMIC to list all processes on a remote computer
This is a simple task to achieve, and you use a DOS command as simple as we have to gradually, so arranged a warm-up task. At the command prompt, typing the following command, we'll see.
Wmic/node:192.168.1.2/user:net process
Explanation:
1 the node and user in the above command are global switches. If you do not want to lose another password, you can also use the password switch, and then write the password on the back (Wmic/node:192.168.1.2/user:net/password:password process). It is important to note that the username and password must be administrator-level and otherwise invalid. WMIC provides a large number of global switches, aliases, verbs, commands, and rich command lines to help enhance the user interface. The global switch is the option to configure the entire WMIC session.
2 process is an individual name, the implementation of a Win32_Process class of WQL query, as to say that is the WMI class is what things, interested in their own find information a lot to understand, if you are lazy, I have time to give you a lecture. Aliases are the middle tier of a simplified syntax for user and WMI namespaces. When you specify an alias, the verb (Verb) represents the action to be performed.
3 If you want, you can add a verb after that, such as LIST full (such as: Wmic/node:192.168.1.2/user:net/password:password process), so you see more clearly.

Tip: A machine with WMIC installed can connect to any machine that has WMI installed, and the connected machine does not need to have WMIC installed.

2. Task two: Turn off local processes with WMIC
Execute the following command to close the running QQ. I am more timid, so dare not close others QQ, can only take my QQ test, if you have enough IQ, if you are more daring, you will soon go to shut someone else's.
WMIC
Process where name= "Qq.exe" call terminate
Explanation:
1 This time we are using interactive methods to carry out the task, the specific interface I do not say more, the picture on the painting than I said much better.
2 call is also a verb, the verb is powerful, the control of the class does not use it, it is a variety of methods can invoke various classes of general. Here we call the Terminate method. Literally you can see that it's vicious.
3 where allows you to query and filter. Find what you want in the super many instances. An instance is a concrete implementation of each class. Each of the processes seen in the previous example is an instance of Win32_Process.

3. Task three: Keep the process information of the remote host in a Web page through WMIC
This task is roughly the same as that of task one, and it is the strengthening of task one. In task one, the information is displayed in the form of text. In addition to the output in text form, WMIC can also return command execution results in other forms, such as XML, HTML, or CSV (comma-delimited text file), as shown in Figure 3. We can typing the following command:
Wmic/output:c:\1.html/node:192.168.1.2/user:net Process List full/format:hform.xsl
Enter Password:* * * *

Explain:
1 The global switch output indicates where the information is stored.
2 The global switch format indicates what format to use, as long as those formats are available, you can refer to the *.xsl file in the C:\WINDOWS\system32\wbem directory, and you don't even have to worry about where they came from. Look next to each other, you can certainly find what you like.

Part two: Using scripts to understand WMI
The command prompt tool is really good, but it does not show that we are masters, the master is able to use the program to achieve the purpose. Below we begin to use the script to achieve our task, the function will be more powerful, the operation will be more flexible.
Whether it's a script or a real program, the following three steps need to be followed to retrieve WMI managed resource information and then query and take advantage of WMI.
1. Connect to the WMI service. Establish a connection to the Windows Management Service on the target computer.
2. Retrieves an instance of a WMI managed resource. Depends primarily on the task to be performed.
3. Displays a WMI instance property and calls its methods.

Current 1/2 page 12 Next read the full text

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.