Home > Web Front-end > JS Tutorial > JavaScript method to obtain client computer hardware and system information_javascript skills

JavaScript method to obtain client computer hardware and system information_javascript skills

WBOY
Release: 2016-05-16 17:05:40
Original
1228 people have browsed it

JavaScript to obtain client computer hardware and system information
Acquire client computer hardware and system information through WMI:

Copy code The 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}
}

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

Win32_DiskDrive // ​​Hard drive

Win32_CDROMDrive // ​​CD 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 // Monitor

Win32_VideoController // Display card detail.

Win32_VideoSettings // Display modes supported by the graphics 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 setting

Win32_BootConfiguration // System startup configuration

Win32_OperatingSystem / / Operating system information

Win32_StartupCommand // System automatic startup program

Win32_Service // System installed services

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

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:
Copy code The code is as follows:

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("");
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 信息
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("");
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() {//键盘信息
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("");
document.write("");
document.write("");
document.write("");
}
document.write("
" p.Description "" p.Name "" p.Status "
");
}

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("");
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 "
");
}


另外,通过以下方式也可以获得系统的相关信息:
复制代码 代码如下:

WMI Scripting HTML













复制代码 代码如下:

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










class Win32_NetworkAdapterConfiguration : CIM_Setting
{
boolean ArpAlwaysSourceRoute;
boolean ArpUseEtherSNAP;
string Caption;
string DatabasePath;
boolean DeadGWDetectEnabled;
string DefaultIPGateway[];
uint8 DefaultTOS;
uint8 DefaultTTL;
string Description;
boolean DHCPEnabled;
datetime DHCPLeaseExpires;
datetime DHCPLeaseObtained;
string DHCPServer; DNSDomainSuffixSearchOrder[];
boolean DNSEnabledForWINSResolution;
string DNSHostName;
string DNSServerSearchOrder[];
boolean DomainDNSRegistrationEnabled;
uint32 ForwardBufferMemory; GatewayCostMetric[];
uint8 IGMPLevel;
uint32 Index;
uint32 InterfaceIndex;
string IPAddress[];
uint32 IPConnectionMetric;
string IPSecPermitIPProtocols[];
string IPSecPermitTCPPorts[];
string IPSecPermitUDPPorts[];
string IPSubnet[];
boolean IPUseZeroBroadcast;
string IPXAddress;
uint32 IPXFrameType[];
uint32 IPXMediaType;
string IPXNetworkNumber[];
string IPXVirtualNetNumber;
uint32 KeepAliveInterval;
uint32 KeepAliveTime; MTU;
uint32 NumForwardPackets;
boolean PMTUBHDetectEnabled;
boolean PMTUDiscoveryEnabled;
string ServiceName;
string SettingID;
uint32 TcpipNetbiosOptions; 32 TcpMaxDataRetransmissions;
uint32 TcpNumConnections;
boolean TcpUseRFC1122UrgentPointer;
uint16 TcpWindowSize;
boolean WINSEnableLMHostsLookup;
string WINSHostupFile;
string WINSPrimaryServer;
string WINSScopeID; 🎜>string WINSSecondaryServer;
};


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template