學習WMI有感

2021-09-30 02:44:39 字數 4431 閱讀 2948

通過兩天的學習發現wmi確實是個好東西:),利用它我們可以很方便的對計算機的硬體資訊進行管理,但是用它得到的硬體資訊十分有限,特別適用於對硬體資訊細節要求不高的使用者,例如一些oem廠商對產線上的產品進行管理和檢測,有了它,從此對那些繁瑣的api說聲byebye了......

下面這幾個小例子是我這兩天的學習心得:

//get lan mac address

static void getlanmacaddress()

", mo["macaddress"].tostring());

mo.dispose();

}console.writeline ("/n/r");

}//get hdd size / serial # / firmware

static void gethddinfo()

", mo["serial number"].tostring());

console.writeline("hdd size/t bytes", mo["size"].tostring());

console.writeline("hdd model/t", mo["model"].tostring());

console.writeline("hdd manufacturer /t", mo["manufacturer"].tostring());

"hdd model/t", mo["firmware"].tostring());

mo.dispose ();

}console.writeline ("/n/r");

}//get cpu info.

static void getcpuinfo()

", mo["processorid"].tostring());

console.writeline("currentclockspeed:/t", mo["currentclockspeed"].tostring());

"l2cachesize:/t", mo["l2cachesize"].tostring());

"l2cachespeed:/t", mo["l2cachespeed"].tostring());

console.writeline("description:/t", mo["description"].tostring());

console.writeline("processortype:/t", mo["processortype"].tostring());

console.writeline("version:/t", mo["version"].tostring());

console.writeline("revision:/t", mo["revision"].tostring());

console.writeline("manufacturer:/t", mo["manufacturer"].tostring());

cpuinfo);

}console.writeline ("/n/r");

}//get cahce info.

static void getcacheinfo()

", mo["maxcachesize"].tostring());

console.writeline("location:/t", mo["purpose"].tostring());

}console.writeline ("/n/r");

}//get memory info.

static void getmemoryinfo()

", mo["capacity"].tostring());

console.writeline("devicelocator:/t", mo["devicelocator"].tostring());

console.writeline("description:/t", mo["description"].tostring());

}console.writeline ("/n/r");

}//get the battery info.

static void getbatteryinfo()

", mo["batteryrechargetime"].tostring());

"devicelocator:/t", mo["batterystatus"].tostring());

console.writeline("description:/t", mo["chemistry"].tostring());

}console.writeline ("/n/r");

}//get the lcd info.

static void getlcdinfo()

", mo["description"].tostring());

console.writeline("pixelsperxlogicalinch:/t", mo["pixelsperxlogicalinch"].tostring());

console.writeline("pixelsperylogicalinch:/t", mo["pixelsperylogicalinch"].tostring());

console.writeline("manufacturer:/t", mo["monitormanufacturer"].tostring ()); //

console.writeline("monitortype:/t", mo["monitortype"].tostring());

console.writeline("screenheight:/t", mo["screenheight"].tostring());

console.writeline("screenwidth:/t", mo["screenwidth"].tostring ());//datetime to string

}console.writeline ("/n/r");

}//get the bios info.

static void getbiosinfo()

", mo["version"].tostring());

"devicelocator:/t", mo["buildnumber"].tostring());

console.writeline("biosversion:/t", mo["biosversion"].tostring ()); //

console.writeline("manufacturer:/t", mo["manufacturer"].tostring());

console.writeline("serialnumber:/t", mo["serialnumber"].tostring());

"installdate:/t", (mo["installdate"].tostring ());//datetime to string

}console.writeline ("/n/r");

}//get hdd serialnum

public static void gethd()

);managementobjectcollection mycollection = wmisearcher.get();

managementobjectcollection.managementobjectenumerator em =

mycollection.getenumerator();

em.movenext();

managementbaseobject mo = em.current;

string id = mo.properties["pnpdeviceid"].value.tostring().trim();

console.writeline("my harddisk is : " + id);

}//get monitor info.

public static void getmonitorinfo()

", mo["description"].tostring());

console.writeline("displayfrequency:/t", mo["displayfrequency"].tostring());

console.writeline("pelsheight:/t", mo["pelsheight"].tostring());

console.writeline("pelswidth:/t", mo["pelswidth"].tostring ()); //

"monitortype:/t", mo["monitortype"].tostring());

"screenheight:/t", mo["screenheight"].tostring());

"screenwidth:/t", mo["screenwidth"].tostring ());//datetime to string

}console.writeline ("/n/r");

}

學習WMI的心得

1.首先了解什麼是wmi wmi最初於 1998 年作為乙個附加元件與 windows nt 4.0 service pack 4 一起發行,是內建在 windows 2000 windows xp 和 windows server 2003 系列作業系統中核心的管理支援技術。基於由 distrib...

WMI 02 常用WMI查詢列表

win32 processor,cpu 處理器 win32 physicalmemory,物理記憶體條 win32 keyboard,鍵盤 win32 pointingdevice,點輸入裝置,包括滑鼠。win32 floppydrive,軟盤驅動器 win32 diskdrive,硬碟驅動器 wi...

學習英語有感

自考結束,我又開始了我學習英語的道路,我們開始了單詞的解析學習,學習音標 我們最開始是吧單個句子拎出來,然後把單詞拿出來,把我們學習的音標應用到單詞中,通過練習,我們就學會了音標。學習單詞 現在我們也是跟這個學習流程一樣,我們依然是把單個的單詞拿出來,然後把這個單詞分解,分成詞根詞綴,每個單詞都會有...