这个问题不是一般的困扰
从微软MSDN上找到一段脚本,想转到C#,却无能为力strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.SWbemRefresher")
Set colDiskDrives = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfDisk_LogicalDisk").objectSet
objRefresher.Refresh
For i = 1 to 500
For Each objDiskDrive in colDiskDrives
Wscript.Echo "Drive name: " & objDiskDrive.Name
Wscript.Echo "Disk bytes per second: " & objDiskDrive.DiskBytesPerSec
Wscript.Sleep 2000
objRefresher.Refresh
Next
Next
--------------------编程问答-------------------- 知道使用system.manager类 --------------------编程问答-------------------- WMI的啊你参考下面的改啊 不行的话 网上直接搜啊 只是WMI类及方法的使用而已
using System;--------------------编程问答-------------------- 你搜到的是用VBScript写的代码,C#可以实现同样的功能,但是语法表达上肯定不同了。
using System.Management;
// This example demonstrates reading a property of a ManagementObject.
class Sample_ManagementObject
{
public static int Main(string[] args)
{
ManagementObject disk = new ManagementObject(
"win32_logicaldisk.deviceid=\"c:\"");
disk.Get();
Console.WriteLine("Logical Disk Size = " + disk["Size"] + " bytes");
Console.ReadLine();
return 0;
}
}
(2)获取CPU信息
public string cpuinfo()
{
string a="";
ManagementClass mcobject = new ManagementClass("Win32_Processor");
ManagementObjectCollection moc = mcobject.GetInstances();
foreach(ManagementObject mo in moc)
{
a += "CPU:" + mo.Properties["ProcessorId"].Value.ToString() + "n";
}
return a;
}
补充:.NET技术 , C#