function getSysInfo(){ var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("." ); //CPU information var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item(); var cpuType=cpu.Name,hostName=cpu.SystemName ; //Memory information var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory")); for (var mem=[],i=0;!memory.atEnd( );memory.moveNext()) mem[i ]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed} //System information var system =new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item(); var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024),curUser=system.UserName,cpuCount=system. NumberOfProcessors
The code implementation mainly includes These parts:
First access the WbemScripting object through new ActiveXObject ("WbemScripting.SWbemLocator");. Connect to our local computer through locator.ConnectServer("."); (. represents the local computer, of course can also access other computers). Get the record set of the object we need through service.ExecQuery("SELECT * FROM Win32_Processor"), a SQL-like statement (in fact, the system information is also stored in a database-like file in the calculation). Use new Enumerator to create an enumerable object, and then you can traverse to get the information.
Note: The prerequisite for running is to modify the browser security settings to "Allow the running of ActiveX scripts that are not marked as safe for execution". The main information here is CPU, memory and system user. You can use WMI API or JSEDIT to get more information. Classes for common information are listed below:
Win32_Processor // CPU processor
Win32_PhysicalMemory // Physical memory
Win32_Keyboard // Keyboard
Win32_PointingDevice / / Point input device, such as mouse
WMI For complete information and detailed list of Win32 classes, please refer to MSDN: http: //msdn2.microsoft.com/en-us/library/aa394084(VS.85).aspx Example:
function button1_onclick() {//cpu 信息 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); var properties = service.ExecQuery("SELECT * FROM Win32_Processor"); var e = new Enumerator (properties); document.write("
"); for (;!e.atEnd();e.moveNext ()) { var p = e.item (); document.write("
"); document.write("
" p.Caption "
"); document.write("
" p.DeviceID "
"); document.write("
" p.Name "
"); document.write("
" p.CpuStatus "
"); document.write("
" p.Availability "
"); document.write("
" p.Level "
"); document.write("
" p.ProcessorID "
"); document.write("
" p.SystemName "
"); document.write("
" p.ProcessorType "
"); document.write("
"); } document.write("
"); }
function Button2_onclick() {//CD-ROM 信息 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive"); var e = new Enumerator (properties); document.write("
"); for (;!e.atEnd();e.moveNext ()) { var p = e.item (); document.write("
"); document.write("
" p.Caption "
"); document.write("
" p.Description "
"); document.write("
" p.Drive "
"); document.write("
" p.Status "
"); document.write("
" p.MediaLoaded "
"); document.write("
"); } document.write("
"); }
function Button3_onclick() {//键盘信息 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard"); var e = new Enumerator (properties); document.write("
"); for (;!e.atEnd();e.moveNext ()) { var p = e.item (); document.write("
"); document.write("
" p.Description "
"); document.write("
" p.Name "
"); document.write("
" p.Status "
"); document.write("
"); } document.write("
"); }
function Button4_onclick() {//主板信息 var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard"); var e = new Enumerator (properties); document.write("
"); for (;!e.atEnd();e.moveNext ()) { var p = e.item (); document.write("
In fact, the most important thing is to use two ActiveX:
< ;OBJECT id=foo classid=CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223> However, these two ActiveXs come with the system, so there is no need to download or register them. The next step is to use script to interact with ActiveX
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn