How to obtain client computer hardware and system information using JavaScript

Source: Internet
Author: User
How to use JavaScript to obtain client computer hardware and system information
WMI is used to obtain the hardware and system information of the client computer:

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 }}

The code implementation mainly includes the following parts:

Access the WbemScripting object through new ActiveXObject ("WbemScripting. SWbemLocator.
Connect to our local computer through locator. ConnectServer (".").
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 file similar to a database in the computation) gets the record set of the desired object.
Use new Enumerator to create an enumerative object. You can traverse the information below.

Note: The prerequisite for running is to modify the browser security settings, "allow ActiveX attacks that are not marked as safe to be executed
Script running ".
Here we mainly take the CPU, memory, and System User information. You can use WMI APIs or JSEDIT to obtain
To more information. Classes of common information are listed below:

Win32_Processor // CPU Processor

Win32_PhysicalMemory // physical memory

Win32_Keyboard // keyboard

Win32_PointingDevice // enter the device, such as the mouse

Win32_DiskDrive // hard drive

Win32_CDROMDrive // Optical Drive

Win32_BaseBoard // Motherboard

Win32_BIOS // BIOS chip

Win32_ParallelPort // parallel port

Win32_SerialPort // serial port

Win32_SoundDevice // multimedia settings

Win32_USBController // USB controller

Win32_NetworkAdapter // Network Adapter

Win32_NetworkAdapterConfiguration // network adapter settings

Win32_Printer // printer

Win32_PrinterConfiguration // printer settings

Win32_PrintJob // printer task

Win32_TCPIPPrinterPort // printer port

Win32_POTSModem // MODEM

Win32_POTSModemToSerialPort // MODEM Port

Win32_DesktopMonitor // display

Win32_VideoController // graphics card details.

Win32_VideoSettings // Display Mode Supported by the video card.

Win32_TimeZone // Time Zone

Win32_SystemDriver // driver

Win32_DiskPartition // disk partition

Win32_LogicalDisk // Logical Disk

Win32_LogicalMemoryConfiguration // logical memory configuration

Win32_PageFile // system page file information

Win32_PageFileSetting // page File Settings

Win32_BootConfiguration // system startup configuration

Win32_OperatingSystem // operating system information

Win32_StartupCommand // the system automatically starts the program.

Win32_Service // system-installed Service

Win32_Group // System Management Group

Win32_GroupUser // system group account

Win32_UserAccount // User Account

Win32_Process // system process

Win32_Thread // system thread

Win32_Share // share

Win32_NetworkClient // installed network client

Win32_NetworkProtocol // installed network protocol

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

Example:

Function button1_onclick () {// cpu information 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 ("
 
 
  
  
"); (;! E. atEnd (); e. moveNext () {var p = e. item (); document. write ("
  
  
     "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
    "); Document. write (" 
   ");} Document. write (" 
  
"+ P. Caption +""+ P. DeviceID +""+ P. Name +""+ P. CpuStatus +""+ P. Availability +""+ P. Level +""+ P. ProcessorID +""+ P. SystemName +""+ P. ProcessorType +"
");} Function Button2_onclick () {// CD-ROM information 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 (" "); (;! E. atEnd (); e. moveNext () {var p = e. item (); document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" ");} Document. write ("
"+ P. Caption +""+ P. Description +""+ P. Drive +""+ P. Status +""+ P. MediaLoaded +"
");} Function Button3_onclick () {// keyboard information 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 (" "); (;! E. atEnd (); e. moveNext () {var p = e. item (); document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" ");} Document. write ("
"+ P. Description +""+ P. Name +""+ P. Status +"
");} Function Button4_onclick () {// motherboard information 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 (" "); (;! E. atEnd (); e. moveNext () {var p = e. item (); document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" "); Document. write (" ");} Document. write ("
"+ P. HostingBoard +""+ P. Manufacturer +""+ P. PoweredOn +""+ P. Product +""+ P. SerialNumber +""+ P. Version +"
");}

In addition, the system information can be obtained through the following methods:

WMI Scripting HTML 
  

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.