wmi如何查内存大小,
谢谢
谢谢
解决方案 »
- 怎么强行停止BEGINRECEIVE过程(不是关闭SOCKET哦)
- 正则和策略模式的2个小问题
- 将execl转换成二进制流再转换成字符串,然后再从字符串转换回execl
- 老板说要在软件里面加数字签名,把软件搞成二进制,算个哈希值出来什么的 , 我实在听不懂,所以请教大家
- 求个正则表达式的问题
- 当前平台不支持“serviceconfig” --在线等!!感谢!
- c# 关于多线程编程的
- 请教关于注册C#开发的DLL问题
- 高手进来看一下
- 关于picturebox,怎样用代码连接一个图片?
- enum 型变量的求教
- 用C#设计windows应用程序,在设计试图里面,为什么看不到panel的Alignment 属性
http://www.codeproject.com/csharp/wmi.asp
{
//Set up a handler for the asynchronous callback
ManagementOperationObserver observer = new
ManagementOperationObserver();
completionHandler.MyHandler completionHandlerObj = new
completionHandler.MyHandler();
observer.ObjectReady += new ObjectReadyEventHandler
(completionHandlerObj.Done); string stringMachineName = ""; //Connect to the remote computer
ConnectionOptions co = new ConnectionOptions(); if (radioMachine.Checked == true)
{
stringMachineName = "localhost";
}
else
{
stringMachineName = textIP.Text;
} if (stringMachineName.Trim().Length == 0)
{
MessageBox.Show("Must enter machine IP address or name.");
return;
} //get user and password
if (textUserID.Text.Trim().Length > 0)
{
co.Username = textUserID.Text;
co.Password = textPassword.Text;
} //Point to machine
System.Management.ManagementScope ms = new System.
Management.ManagementScope("\\\\" +
stringMachineName + "\\root\\cimv2", co);
//get process path
ManagementPath path = new ManagementPath( "Win32_Process"); //Get the object on which the method will be invoked
ManagementClass processClass = new ManagementClass
(ms,path,null); //Status
updateStatus("Create process " + stringCommandLine + ".");
//Create an array containing all arguments for the method
object[] methodArgs = {stringCommandLine, null, null, 0}; //Execute the method
processClass.InvokeMethod (observer, "Create", methodArgs); //wait until invoke method is complete or 5 sec timeout
int intCount = 0;
while (!completionHandlerObj.IsComplete)
{
if (intCount > 10)
{
MessageBox.Show("Create 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
//check for error
if (completionHandlerObj.ReturnObject.Properties
["returnValue"].Value.ToString() == "0")
{
//refresh process list
this.Refresh();
}
else
{
MessageBox.Show("Error creating new process.",
"Create New Process");
}
} //Status
updateStatus("Ready");
this.Update();
}
foreach (ManagementBaseObject obj in seacher.Get())
{
listBox1.Items.Add("物理内存:" + obj["TotalPhysicalMemory"].ToString());
listBox1.Items.Add("虚拟内存:" + obj["TotalVirtualMemory"].ToString());
listBox1.Items.Add("页面文件:" + obj["TotalPageFileSpace"].ToString());
}