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 ("
"+ 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 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 ("
"+ 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 () {// 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 ("
"+ P. Description +" | "); Document. write ("
"+ P. Name +" | "); Document. write ("
"+ P. Status +" | "); Document. write ("
");} Document. write ("
");} 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 ("
"+ P. HostingBoard +" | "); Document. write ("
"+ P. Manufacturer +" | "); Document. write ("
"+ P. PoweredOn +" | "); Document. write ("
"+ P. Product +" | "); Document. write ("
"+ P. SerialNumber +" | "); Document. write ("
"+ P. Version +" | "); Document. write ("
");} Document. write ("
");}
In addition, the system information can be obtained through the following methods:
WMI Scripting HTML