Introduced
This is another new book on Windows Management Instrumentation (Windows Management specification) after my last article, "My Explorer." I'm going to show you some techniques that allow you to remotely access the operating systems, services, and currently running processes of other computers on your network, if you have to have administrator privileges on those computers. I will also show you how to use WMI to start or stop a service, terminate a process, and create a process. This is the main interface of the program:
Begin
In this WMI application, I created a library wmicontrollibrary that contained four user controls. These four user controls are explorer,systeminfo,services and processes respectively. Each control has its own specific function. The following is a brief description of each control function:
Explorer control I have converted my ' my Explorer ' to a user control, which is used to display information such as drives, directories, files, etc. on your system.
SystemInfo control * This control is used to display information such as operating system and hardware data and inventory.
Services control * This control is used to display the service currently running on the system.
Process Control * This control is used to display the process currently running by the system.
(* Note: This control can be used to monitor remote systems on the local or network.) )
Each of these controls refers to the System.Management namespace to ensure that they have access to their specific system information.
Controlled State events
Some of these controls take some time to get the relevant information from the system, so I implemented an event UpdateStatus (string e) in each control. This allows each control to update the status bar of the main application form, and the user is well aware of what the control is doing.
//控制内部的代码
//声明一个Status的事件委托类型
public delegate void Status(string e);
//声明了一个更新状态的事件
public event Status UpdateStatus;
//更新状态条
UpdateStatus("Hello world.");
//主程序代码
//用参数中的字符串刷新状态条的显示文本
private void refreshStatusBar(string stringStatus)
{
//更新状态条
statusBarStatus.Text = stringStatus;
}