JavaScript access to information such as client computer hardware and systems

Source: Internet
Author: User
Tags datetime

  for you to explain in detail how to use JavaScript to obtain client computer hardware and system information, there is a good example, interested friends can refer to the following

JavaScript obtains client computer hardware and system Information   obtains client computer hardware and system information through WMI:    code is as follows: 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    Return {cputype:cputype,cpucount:cpucount,hostname:hostname,curuser:curuser, memcap:physicmencap,mem:mem} }    CodeImplementation mainly includes these parts:    first through the new ActiveXObject ("WbemScripting.SWbemLocator"); Access to the WbemScripting object.   through locator. ConnectServer ("."); Connect our local computer (. On behalf of the local computer, of course   can also access other computers).   through service. ExecQuery ("SELECT * from Win32_Processor") This SQL-like statement (in fact the system information is stored in a similar database file in the calculation) gets the recordset of the object we need.   Create an enumerable object with the new enumerator, and you can iterate through the information below.     NOTE: The premise of the operation is to modify the browser security settings, "allow the operation of activex  scripts that are not marked as safe to perform".   Here the CPU, memory and system users have a few information, you use the WMI API or the use of Jsedit to obtain   to more information. The class:    Win32_Processor/CPU processor     win32_physicalmemory//physical memory     Win32_keyboar for common information are listed below d//keyboard     win32_pointingdevice//point input devices, such as mouse     win32_diskdrive//hard drive     win32_cdromdrive Optical drive     Win32_baseboard//motherboard     Win32_BIOS//BIOS chip     Win32_ParallelPort/Port &nbsp ;   Win32_serialport//serial     Win32_sounddevice/Multimedia settings     Win32_usbcontroller//USB controller   &N Bsp Win32_NetworkAdapter//network adapters    Win32_NetworkAdapterConfiguration//network adapter settings     Win32_Printer//printers     Win32_PrinterConfiguration Printer setup     Win32_PrintJob//Printer Tasks     Win32_tcpipprinterport//Printer Port     WIN32_POTSMODEM// modem    Win32_potsmodemtoserialport//MODEM port     Win32_DesktopMonitor/display     WIN32_VI Deocontroller//graphics details.     Win32_videosettings//graphics support display mode.     Win32_TimeZone//time zone     win32_systemdriver//driver     win32_diskpartition//disk partition     Win32_LogicalDisk//Logical Disk     Win32_LogicalMemoryConfiguration//Logical memory configuration     Win32_PageFile//System Paging file information     win32_pagefilesetting//page file Settings     win32_bootconfiguration//System boot configuration     Win32_ OperatingSystem/Os information     Win32_startupcommand//System Autostart program     Win32_Service/system installation Services   &NBSP ; Win32_Group//System administration Group     Win32_groupuser/System group account     WIN32_USERACCOunt//user account     Win32_Process/system process     Win32_thread/system thread     Win32_Share//shared   &NB Sp Win32_NetworkClient//Installed network client     WIN32_NETWORKPROTOCOL//Installed network protocol     WMI For complete information and a detailed list of Win32 classes, refer to msdn:  http://msdn2.microsoft.com/en-us/library/aa394084 (vs.85) .aspx  example:    Code as follows: function Button1_onclick () {//cpu information   var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); nbsp var service = Locator. ConnectServer (".");   var properties = service. ExecQuery ("SELECT * from Win32_Processor");  var e = new Enumerator (properties);  document.write ("<table bo Rder=1> ");  for (;! E.atend (); E.movenext ())   {  var p = e.item ();  document.write ("<tr>");  document.write (" <td> "+ p.caption +" </td> ");  document.write (" <td> "+ P.deviceid +" </td> ");  document.write ("<td>" + p.name + "</td>");  document.write ("<td>" + P.Cpustatus + "</td>");  document.write ("<td>" + p.availability + "</td>");  document.write ( "<td>" + p.level + "</td>");  document.write ("<td>" + P.processorid + "</td>");  document.write ("<td>" + p.systemname + "</td>");  document.write ("<td>" + P.processortype + " </td> ");  document.write (" </tr> "); }  document.write (" </table> "); }    function Button2_onclick () {//cd-rom information   var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); nbsp var service = Locator. ConnectServer (".");   var properties = service. ExecQuery ("SELECT * from win32_cdromdrive");  var e = new Enumerator (properties);  document.write ("<table b Order=1> ");  for (;! E.atend (); E.movenext ())   {  var p = e.item ();  document.write ("<tr>");  document.write (" <td> "+ p.caption + </td>");  document.write ("<td>"+ p.description + "</td>");  document.write ("<td>" + p.drive + "</td>");  document.write ("& Lt;td> "+ p.status +" </td> ");  document.write (" <td> "+ p.medialoaded +" </td> ");  document.write ("</tr>"); }  document.write ("</table>"); }    function Button3 _onclick () {//keyboard info   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 ("<table Bor Der=1> ");  for (;! E.atend (); E.movenext ())   {  var p = e.item ();  document.write ("<tr>");  document.write (" <td> "+ p.description +" </td> ");  document.write (" <td> "+ p.name +" </td> ");  document.write ("<td>" + p.status + "</td>");  document.write ("</tr>"); }  document.write ("</table>"); }    function Button4_onclick () {//motherboard information   var locator = new Active Xobject ("WbemScripting.SWbemLocator");  var service = Locator. ConnectServer (".");   var properties = service. ExecQuery ("SELECT * from Win32_baseboard");  var e = new Enumerator (properties);  document.write ("<table bo Rder=1> ");  for (;! E.atend (); E.movenext ())   {  var p = e.item ();  document.write ("<tr>");  document.write (" <td> "+ P.hostingboard + </td>");  document.write ("<td>" + p.manufacturer + "</td>");   document.write ("<td>" + P.poweredon + "</td>");  document.write ("<td>" + p.product + "<" /TD> ");  document.write (" <td> "+ p.serialnumber +" </td> ");  document.write (" <td> "+ P. Version + "</td>");  document.write ("</tr>"); }  document.write ("</table>");  }      In addition, passThe following ways can also obtain information about the system: The code is as follows:
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.