网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 大学论文导航 设计下载 最新论文 下载排行 原创论文 论文源代码
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > ASP.net > 正文

WMI使用教程(译)

来源:http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/12
ynchronous callback
ManagementOperationObserver observer = new ManagementOperationObserver();
completionHandler.MyHandler completionHandlerObj = new completionHandler.MyHandler();
observer.ObjectReady += new ObjectReadyEventHandler(completionHandlerObj.Done);

//Get ManagementObject for process
queryCollection = getProcessCollection("Select * from Win32_Process Where ProcessID = ''" + ProcessID + "''");

//Status
updateStatus("Invoking terminate process");

foreach ( ManagementObject mo in queryCollection)
{
//start or stop service
mo.InvokeMethod(observer, "Terminate", null);
}

//wait until invoke method is complete or 5 sec timeout
int intCount = 0;
while (!completionHandlerObj.IsComplete)
{
if (intCount == 10)
{
MessageBox.Show("Terminate process timed out.", "Terminate Process Status");
break;
}
//wait 1/2 sec.
System.Threading.Thread.Sleep(500);

//increment counter
intCount++;
}

if (intCount != 10)
{
//InvokeMethod did not time out
if (completionHandlerObj.ReturnObject.Properties["returnValue"].Value.ToString() == "0")
{
lvItem = ProcessItem;
lvItem.Remove();
}
else
{
MessageBox.Show("Error terminating process.", "Terminate Process");
}
}

创建进程:

创建一个新的进程我们需要调用ManagementClass类的InvokeMethod方法来完成
我们可以通过ManagementClass processClass = New ManagementClass(ms,path,null);
这条语句来实现一个ManagementClass对象.ms是一个ManagementScope类的实例;
,path是一个ManagementPath的实例.ManagementScope来设置Management的范围.
ManagementPath用来提供一个包装,用于分析和生成 WMI 对象的路径.("Win32_Process")
在这之前我们还需要调用ManagementClass.InvokeMethod(observer, methodName, inParameters).
我们可以通过一个对象数组来一次传递四个参数.inParameters实际上就是一个
Create Method in Class Win32_Process(参考Platform SDK: Windows Management Instrumentation)
uint32 Create(string CommandLine,
string CurrentDirectory,
Win32_ProcessStartup ProcessStartupInformation,
uint32* ProcessId);
Parameters
CommandLine - [in] Command line to execute. The system adds a null character to the command line, trimming the string if necessary, to indicate which file was actually used.

CurrentDirectory - [in] Current drive and directory for the child process. The string requires that the current directory resolves to a known path. A user can specify an absolute path or a path relative to the current working directory. If this parameter is NULL, the new process will have the same path as the calling process. This option is provided primarily for shells that must start an application and specify the application''s initial drive and working directory.

ProcessStartupInformation - [in] The startup configuration of a Windows process. For more information see Win32_ProcessStartup.

ProcessId - [out] Global process identifier that can be used to identify a process. The value is valid from the time the process is creat

网学推荐

免费论文

原创论文

设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号