JavaScript gets client computer hardware and system Information

Source: Internet
Author: User

JavaScript gets client computer hardware and system Information

To obtain client computer hardware and system information through WMI:

//System Information AcquisitionfunctionGetsysinfo () {varLocator =NewActiveXObject ("WbemScripting.SWbemLocator"); varService = Locator. ConnectServer ("."); //CPU Information    varCPU =NewEnumerator (service. ExecQuery ("SELECT * from Win32_Processor") . Item (); varCputype=cpu. Name,hostname=CPU.     SystemName; //Memory Information    varMemory =NewEnumerator (service. ExecQuery ("SELECT * from Win32_physicalmemory"));  for(varmem=[],i=0;! Memory.atend (); Memory.movenext ()) Mem[i++]={cap:memory.item (). capacity/1024/1024, Speed:memory.item (). Speed}//System Information    varsystem=NewEnumerator (service. ExecQuery ("SELECT * from Win32_ComputerSystem") . Item (); varPhysicmencap=math.ceil (System. totalphysicalmemory/1024/1024), Curuser=system. Username,cpucount=System. NumberOfProcessorsreturn{Cputype:cputype,cpucount:cpucount,hostname:hostname,curuser:curuser,memcap:physicmencap,mem:mem}}

The code implementation mainly includes these parts:  

      1. First through new ActiveXObject ("WbemScripting.SWbemLocator"); Access to the WbemScripting object.
      2. Through locator. ConnectServer ("."); Connect our local computer (.) on behalf of the local computer, of course
      3. You can also access other computers).
      4. Through the service. ExecQuery ("SELECT * from Win32_Processor") This SQL-like statement (in fact the system information is also stored in a database-like file in the calculation) gets the recordset of the object we need.
      5. Using new enumerator to create an enumerable object, you can iterate through the information below.

Note: The prerequisite for the operation is to modify the browser security settings, "Allow ActiveX that is not marked as safe to perform
Script to run ".

Here the main CPU, memory and system users a few information, we use the WMI API or with the help of Jsedit get
to more information. The following is a list of common information classes:

Win32_Processor//CPU Processorwin32_physicalmemory//Physical MemoryWin32_Keyboard//keyboardWin32_pointingdevice//point input device, such as mousewin32_diskdrive//Hard Drivewin32_cdromdrive//Optical DriveWin32_baseboard//MotherboardWin32_BIOS//BIOS ChipWin32_ParallelPort//and the PortWin32_serialport//Serial PortWin32_sounddevice//Multimedia SettingsWin32_usbcontroller//USB ControllerWin32_NetworkAdapter//Network AdapterWin32_NetworkAdapterConfiguration//Network Adapter SettingsWin32_Printer//Printerwin32_printerconfiguration//Printer SettingsWin32_PrintJob//Printer TasksWin32_tcpipprinterport//Printer PortWin32_potsmodem//MODEMWin32_potsmodemtoserialport//MODEM PortWin32_DesktopMonitor//DisplayWin32_VideoController//graphics details. win32_videosettings//display mode supported by the graphics card. Win32_TimeZone//Time ZoneWin32_SystemDriver//Driver Programwin32_diskpartition//Disk PartitioningWin32_LogicalDisk//Logical Diskwin32_logicalmemoryconfiguration//Logical Memory ConfigurationWin32_PageFile//System page File informationwin32_pagefilesetting//page File Settingswin32_bootconfiguration//System Boot ConfigurationWin32_OperatingSystem//Operating System InformationWin32_startupcommand//System Auto-Start programWin32_Service//System-Installed servicesWin32_Group//System Management GroupWin32_groupuser//System Group AccountWin32_UserAccount//User AccountWin32_Process//System ProcessesWin32_thread//System ThreadsWin32_Share//sharedwin32_networkclient//Installed network ClientsWin32_NetworkProtocol//Installed network Protocols

For complete information and a detailed list of WMI Win32 classes, refer to MSDN:
http://msdn2.microsoft.com/en-us/library/aa394084 (vs.85). aspx
Example:

functionButton1_onclick () {//CPU Information      varLocator =NewActiveXObject ("WbemScripting.SWbemLocator"); varService = Locator. ConnectServer ("."); varProperties = Service. ExecQuery ("SELECT * from Win32_Processor"); varE =NewEnumerator (properties); document.write ("<table border=1>");  for(;!e.atend (); E.movenext ()) {            varp =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>");}functionButton2_onclick () {//CD-ROM information      varLocator =NewActiveXObject ("WbemScripting.SWbemLocator"); varService = Locator. ConnectServer ("."); varProperties = Service. ExecQuery ("SELECT * from Win32_CDROMDrive"); varE =NewEnumerator (properties); document.write ("<table border=1>");  for(;!e.atend (); E.movenext ()) {            varp =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 ("<td>" + p.status + "</td>"); document.write ("<td>" + p.medialoaded + "</td>"); document.write ("</tr>"); } document.write ("</table>");}functionButton3_onclick () {//Keyboard Information      varLocator =NewActiveXObject ("WbemScripting.SWbemLocator"); varService = Locator. ConnectServer ("."); varProperties = Service. ExecQuery ("SELECT * from Win32_Keyboard"); varE =NewEnumerator (properties); document.write ("<table border=1>");  for(;!e.atend (); E.movenext ()) {            varp =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>");}functionButton4_onclick () {//Motherboard Information      varLocator =NewActiveXObject ("WbemScripting.SWbemLocator"); varService = Locator. ConnectServer ("."); varProperties = Service. ExecQuery ("SELECT * from Win32_baseboard"); varE =NewEnumerator (properties); document.write ("<table border=1>");  for(;!e.atend (); E.movenext ()) {            varp =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>");}

JavaScript gets client computer hardware and system Information

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.