Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of WMI_Vbs script programming

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the example analysis of WMI_Vbs script programming, the article is very detailed, has a certain reference value, interested friends must read it!

WMI is Microsoft Windows Management Instrumentation. The Chinese name is Windows Management Specification. Since Windows 2000, WMI (Windows Management Specification) has been built into the operating system and has become an important part of Windows system management. So it's easy for people to see it, because we should at least be users of Windows 2000.

What can WMI do?

WMI can not only get the desired computer data, but also can be used for remote control. Remote control of computers is something that everyone likes. The common practice of many remote monitoring and control software is to run the server-side background program on the remote computer and a client-side control program on the local computer, and realize the remote control of the computer through the collusion of the two programs. The disadvantage of this approach is very obvious, when the server program is turned off, this kind of remote monitoring can not be realized, because there is no insider. The remote monitoring and control realized by WMI does not need to install anything else on the server side at all, so the system turns on the WMI service by default. Specifically, the capabilities of WMI are as follows:

1. Get the hardware and software information of the local and remote computers.

2. Monitor the operation of software and services on local and remote computers.

3. Control the operation of software and services on local and remote computers.

4. Advanced applications.

How do I access WMI?

When we know some of WMI's skills, we already want to know how to know him and take advantage of him. There are many ways to take advantage of WMI. To put it simply, there are three ways:

1. Realize common query and operation through various tools provided to us by Microsoft. It mainly includes the WMIC under the command prompt, and the WMI TOOL provided by Microsoft. You can download it from Microsoft's website for free. Of course, I can also provide it to you for free.

2. Write your own scripts to achieve more flexible operations. To be really flexible and practical, familiarity with WSH scripts is necessary. Of course, it doesn't matter if you are not familiar with it. I will explain it in detail later.

3. Access and operate it by writing our own program. Any language is fine. It's easier to use .NET programs, and it's more complicated to use VC, etc. At least that's what I think.

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 tools, and you can find a lot of answers in it. However, these things are generally not suitable for our novice to play, feeling a little scary.

Our mission today?

Today we have five tasks:

Task 1: use WMIC to list all processes on the remote computer.

Task 2: use WMIC to shut down the local process.

Task 3: save the process information of the remote host in a web page through WMIC

Task 4: use scripts to monitor each other's processes in real time

Task 5: use scripts to open sharing to each other

Check and monitor the progress, kill the process, and finally give each other a share. Our friend is about to do all the bad things. Once we understand our mission, we can hit the road. This time we will mainly use WMIC and scripts to accomplish our task, so we will mainly explain it in two parts. In the actual combat of the five tasks, we will understand it more deeply. It doesn't matter if there is no foundation. I will try my best to explain all the so-called foundations so that you can easily communicate with this friend.

The first part: using WMIC to know WMI.

WMIC is short for Windows Management Instrumentation Commandline. WMIC extends WMI and provides support for system administration from command line interfaces and batch command scripts. Provides a powerful and friendly command line interface for WMI namespaces. With WMIC,WMI, it becomes approachable.

Executing the "WMIC" command starts the WMIC command line environment. The first time you execute the WMIC command, Windows first installs WMIC and then displays a command line prompt for WMIC. At the WMIC command line prompt, the command is executed interactively. If you don't know how to interact with it, please hit "/?" and read all the instructions carefully and you will know. 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 1: use WMIC to list all processes on the remote computer

This is a very simple task to implement, as simple as you use a DOS command, because we have to step by step, so we have arranged such a warm-up task. Type the following command at the command prompt, and we will see.

WMIC / node:192.168.1.2 / user:net process

Commentary:

1) NODE and USER in the above command are global switches. If you don't want to type your password again, you can also use the PASSWORD switch and write the password after it (WMIC / node:192.168.1.2 / user:net / password:password process). It is important to note that the user name and password here must be administrator level, the other invalid. WMIC provides a large number of global switches, aliases, verbs, commands, and a rich command line to help enhance the user interface. The global switch is an option to configure the entire WMIC session.

2) Process is an alias, executed a Win32_process class WQL query, as for what the WMI class is, if you are interested, find your own information and learn more, if you are lazy, just wait until I have time to explain it to you. Aliases are the middle layer of simplified syntax between users and WMI namespaces. When you specify an alias, the verb (Verb) indicates the action to be performed.

3) if you like, you can add a verb after it, such as LIST FULL (e.g. WMIC / node:192.168.1.2 / user:net / password:password process), so that you can see it more clearly.

Tip: a machine with WMIC installed can be connected to any machine with WMI installed, and the connected machine does not need to install WMIC.

2. Task 2: shut down the local process using WMIC

Executing the following command will close the running QQ. I am relatively timid, so I dare not turn off other people's QQ, so I can only experiment with my QQ. If you have enough IQ and courage, you will soon lock up other people's.

WMIC

Process where name= "qq.exe" call terminate

Commentary:

1) this time we use an interactive method to carry out the task. I won't say much about the specific interface. The picture is much better than I said.

2) Call is also a verb, this verb is powerful, the control class does not use it, it is a general who can call all kinds of methods. Here we call the terminate method. Literally, you can see that it is vicious.

3) Where allows you to query and filter. Find what you want in a super large number of examples. An instance refers to the concrete implementation of each class. Each of the processes seen in the previous example is an instance of WIN32_PROCESS.

3. Task 3: save the process information of the remote host in a web page through WMIC

This task is roughly the same as that in Task 1, which is the strengthening of Task 1. In Task 1, the information is displayed as text. In fact, in addition to the text output, WMIC can return the result of command execution in other forms, such as XML, HTML, or CSV (a comma-delimited text file), as shown in figure 3. We can type in the following command:

Wmic / output:C:\ 1.html / node:192.168.1.2 / user:net process list full / format:hform.xsl

Enter the password: *

Explanation:

1) the global switch OUTPUT indicates where to store this information.

2) the global switch FORMAT indicates which formats to use. As for which formats are available, you can refer to the * .xsl files in the C:\ WINDOWS\ system32\ wbem directory. You don't even care where they come from, just use them. If you look next to each other, you will find what you like.

Part two: using scripts to understand WMI

The tool at the command prompt is really easy to use, but it doesn't show that we are experts, and experts can use programs to achieve their goals. Let's start to use scripts to implement our tasks, which will be more powerful and more flexible.

Whether a script or a real program, to retrieve WMI managed resource information and then query and utilize WMI, you need to follow the following three steps.

1. Connect to the WMI service. Establish a connection to the Windows management service on the target computer.

2. Retrieve the instance of the WMI managed resource. It mainly depends on the task to be performed.

3. Display the properties of an instance of WMI and call its methods.

The above is all the content of the article "sample Analysis of WMI_Vbs scripting programming". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report