JavaScript 獲取客戶端計算機硬件及系統(tǒng)信息
當前位置:點晴教程→知識管理交流
→『 技術(shù)文檔交流 』
通過WMI來實現(xiàn)獲取客戶端計算機硬件及系統(tǒng)信息:
1//系統(tǒng)信息獲取 2function getSysInfo(){ 3 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 4 var service = locator.ConnectServer("."); 5 //CPU信息 6 var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item(); 7 var cpuType=cpu.Name,hostName=cpu.SystemName; 8 //內(nèi)存信息 9 var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); 10 for (var mem=[],i=0;!memory.atEnd();memory.moveNext()) mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed} 11 //系統(tǒng)信息 12 var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item(); 13 var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024),curUser=system.UserName,cpuCount=system.NumberOfProcessors 14 15 return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem} 16} 代碼實現(xiàn)主要包括這幾部分: 注意:運行的前提是要修改瀏覽器安全設(shè)置,“允許對未標記為可安全執(zhí)行的ActiveX 到更多的信息。下面列出了常用信息的類: Win32_Processor // CPU 處理器 Win32_PhysicalMemory // 物理內(nèi)存 Win32_Keyboard // 鍵盤 Win32_PointingDevice // 點輸入設(shè)備,如鼠標 Win32_DiskDrive // 硬盤驅(qū)動器 Win32_CDROMDrive // 光盤驅(qū)動器 Win32_BaseBoard // 主板 Win32_BIOS // BIOS 芯片 Win32_ParallelPort // 并口 Win32_SerialPort // 串口 Win32_SoundDevice // 多媒體設(shè)置 Win32_USBController // USB 控制器 Win32_NetworkAdapter // 網(wǎng)絡(luò)適配器 Win32_NetworkAdapterConfiguration // 網(wǎng)絡(luò)適配器設(shè)置 Win32_Printer // 打印機 Win32_PrinterConfiguration // 打印機設(shè)置 Win32_PrintJob // 打印機任務(wù) Win32_TCPIPPrinterPort // 打印機端口 Win32_POTSModem // MODEM Win32_POTSModemToSerialPort // MODEM 端口 Win32_DesktopMonitor // 顯示器 Win32_VideoController // 顯卡細節(jié)。 Win32_VideoSettings // 顯卡支持的顯示模式。 Win32_TimeZone // 時區(qū) Win32_SystemDriver // 驅(qū)動程序 Win32_DiskPartition // 磁盤分區(qū) Win32_LogicalDisk // 邏輯磁盤 Win32_LogicalMemoryConfiguration // 邏輯內(nèi)存配置 Win32_PageFile // 系統(tǒng)頁文件信息 Win32_PageFileSetting // 頁文件設(shè)置 Win32_BootConfiguration // 系統(tǒng)啟動配置 Win32_OperatingSystem // 操作系統(tǒng)信息 Win32_StartupCommand // 系統(tǒng)自動啟動程序 Win32_Service // 系統(tǒng)安裝的服務(wù) Win32_Group // 系統(tǒng)管理組 Win32_GroupUser // 系統(tǒng)組帳號 Win32_UserAccount // 用戶帳號 Win32_Process // 系統(tǒng)進程 Win32_Thread // 系統(tǒng)線程 Win32_Share // 共享 Win32_NetworkClient // 已安裝的網(wǎng)絡(luò)客戶端 Win32_NetworkProtocol // 已安裝的網(wǎng)絡(luò)協(xié)議 WMI Win32類的完整信息及詳細列表請參考MSDN: 1function button1_onclick() {//cpu 信息 2 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 3 var service = locator.ConnectServer("."); 4 var properties = service.ExecQuery("SELECT * FROM Win32_Processor"); 5 var e = new Enumerator (properties); 6 document.write("<table border=1>"); 7 for (;!e.atEnd();e.moveNext ()) 8 { 9 var p = e.item (); 10 document.write("<tr>"); 11 document.write("<td>" + p.Caption + "</td>"); 12 document.write("<td>" + p.DeviceID + "</td>"); 13 document.write("<td>" + p.Name + "</td>"); 14 document.write("<td>" + p.CpuStatus + "</td>"); 15 document.write("<td>" + p.Availability + "</td>"); 16 document.write("<td>" + p.Level + "</td>"); 17 document.write("<td>" + p.ProcessorID + "</td>"); 18 document.write("<td>" + p.SystemName + "</td>"); 19 document.write("<td>" + p.ProcessorType + "</td>"); 20 document.write("</tr>"); 21 } 22 document.write("</table>"); 23} 24 25function Button2_onclick() {//CD-ROM 信息 26 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 27 var service = locator.ConnectServer("."); 28 var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive"); 29 var e = new Enumerator (properties); 30 document.write("<table border=1>"); 31 for (;!e.atEnd();e.moveNext ()) 32 { 33 var p = e.item (); 34 document.write("<tr>"); 35 document.write("<td>" + p.Caption + "</td>"); 36 document.write("<td>" + p.Description + "</td>"); 37 document.write("<td>" + p.Drive + "</td>"); 38 document.write("<td>" + p.Status + "</td>"); 39 document.write("<td>" + p.MediaLoaded + "</td>"); 40 document.write("</tr>"); 41 } 42 document.write("</table>"); 43} 44 45function Button3_onclick() {//鍵盤信息 46 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 47 var service = locator.ConnectServer("."); 48 var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard"); 49 var e = new Enumerator (properties); 50 document.write("<table border=1>"); 51 for (;!e.atEnd();e.moveNext ()) 52 { 53 var p = e.item (); 54 document.write("<tr>"); 55 document.write("<td>" + p.Description + "</td>"); 56 document.write("<td>" + p.Name + "</td>"); 57 document.write("<td>" + p.Status + "</td>"); 58 document.write("</tr>"); 59 } 60 document.write("</table>"); 61} 62 63function Button4_onclick() {//主板信息 64 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); 65 var service = locator.ConnectServer("."); 66 var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard"); 67 var e = new Enumerator (properties); 68 document.write("<table border=1>"); 69 for (;!e.atEnd();e.moveNext ()) 70 { 71 var p = e.item (); 72 document.write("<tr>"); 73 document.write("<td>" + p.HostingBoard + "</td>"); 74 document.write("<td>" + p.Manufacturer + "</td>"); 75 document.write("<td>" + p.PoweredOn + "</td>"); 76 document.write("<td>" + p.Product + "</td>"); 77 document.write("<td>" + p.SerialNumber + "</td>"); 78 document.write("<td>" + p.Version + "</td>"); 79 document.write("</tr>"); 80 } 81 document.write("</table>"); 82} 83 84 該文章在 2014/11/4 18:17:57 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |