JavaScript obtain client computer hardware and system information
Through WMI to obtain client computer hardware and system information:
Copy code code as follows:
function getsysinfo () {
var local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.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.itemm () .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.numberProcessors
Return {CPUTYPE: CPUTYPE, CPUCOUNT: CPUCOUNT, Hostname: Hostname, Curuser: Curuser, Memcap: PhysicMencap, Mem: Mem}
}
Code implementation mainly includes these parts:
First pass the New Activexobject ("WBEMSCRIPTING.SWBEMLOCator"); access the WBEMScripting object.
Through local.connectserver (".");
You can also access other computers).
Through service.execquery ("Select * from Win32_processor"), a similar SQL statement (in fact, system information is also stored in a database -like file in calculations) to obtain the record set we need.
Create an enumerated object through New Enumertor, and you can traverse information below.
Note: The premise of running is to modify the safety settings of the browser, "allowing ActiveX, which is not marked as safe,"
The operation of the script ".
Here are the main information of CPU, memory, and system users.
To more information. The class of common information is 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 driver
Win32_cdromdrive // CD drive
Win32_baseboard // motherboard
Win32_bios // BIOS chip
Win32_parallelport //
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 // The display mode supported by the graphics card.
Win32_timezone // time zone
Win32_systemDriver // Driver
Win32_diskpartition // disk partition
Win32_logicalDISK // Logic 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 automatic startup program
Win32_Service // System installation service
Win32_group // System Management Group
Win32_groupuser // System group account number
Win32_useraccount // User account
Win32_process // System process
Win32_thread // System thread
Win32_share // Share
Win32_networkClient // The installed online client
Win32_networkprotocol // The installed network protocol
For complete information and detailed lists of WMI Win32 class, please refer to MSDN:
http://msdn2.microsoft.com/en-s/library/aa394084 (vs.85).aspx
Example:
Copy code code as follows:
Function Button1_ONCLICK () {// CPU information
var local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.connectserver (".");
Var Properties = Service.execquery ("Select * from Win32_Processor");
var e = New Enumerator (Properties);
document.write ("<table border = 1>");
for (;! E.atend (); e.movenext ())
{{
var p = e.item ();
document.write ("<ter>");
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 local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.connectserver (".");
Var Properties = Service.execquery ("Select * from win32_cdromdrive");
var e = New Enumerator (Properties);
document.write ("<table border = 1>");
for (;! E.atend (); e.movenext ())
{{
var p = e.item ();
document.write ("<ter>");
document.write ("<TD>" + P.caption + "</td>");
document.write ("<TD>" " + P.Descript +" </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>");
}
Function Button3_ONCLICK () {// Keyboard information
var local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.connectserver (".");
Var Properties = Service.execquery ("Select * from Win32_Keyboard");
var e = New Enumerator (Properties);
document.write ("<table border = 1>");
for (;! E.atend (); e.movenext ())
{{
var p = e.item ();
document.write ("<ter>");
document.write ("<TD>" " + P.Descript +" </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 local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.connectserver (".");
Var Properties = Service.execquery ("Select * from Win32_baseboard");
var e = New Enumerator (Properties);
document.write ("<table border = 1>");
for (;! E.atend (); e.movenext ())
{{
var p = e.item ();
document.write ("<ter>");
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. P. P. P. P." </td> ");
document.write ("<TD>" " + P.Version +" </td> ");
document.write ("</tr>);
}
document.write ("</table>");
}
In addition, you can also obtain the relevant information through the following ways:
Copy code code as follows:
<Html> <head> <title> WMI Scripting html </title>
<Meta http-equiv = content-type content = "text/html; charset = gb2312">
<Script language = jscript event = "Oncompleted (Hresult, PerrorObject, PasyncContext)" for = FOO>
document.Forms [0] .txtMacadr.Value = Unescape (macaddr);
document.Forms [0] .txtipaddr.Value = Unescape (iPaddr);
document.Forms [0] .txtdnsname.value = Unescape (sdnsname);
//document.Formbar.submit ();
</Script>
<script language = jscript event = OnObjectReady (ObjObject, ObjasyncContext) for = FOO>
if (ObjObject.iPenabled! = NULL && Objobject.ipenabled! = "Undefined" && Objobject.iPenabled == TRUE)
{{
If (Objobject.macaddress! = NULL && Objobject.macaddress! = "Undefined")
Macaddr = object.macaddress;
if (ObjObject.iPenabled && Objobject.ipaddress (0)! = Null && Objobject.IPADDDRESS (0)! = "Undefined")
Ipaddr = object.ipaddress (0);
if (Objobject.dnshostname! = Null && Objobject.dnshostname! = "Undefined")
sdnsname = object.dnshostname;
}
</Script>
<Meta content = "mshtml 6.00.2800.1106" name = generator> </head>
<body>
<Object ID = local classid = clsid: 76A64158-CB41-11D1-8B02-00600806D9B6 Viewastext> </Object>
<Object ID = FOO Classid = CLSID: 75718C9A-F029-11D1-A1AC-004FB6C223> </Object>
<script language = jscript>
var service = local.connectserver ();
var macaddr;
var iPaddr;
var domainddr;
var sdnsname;
Service.Security_.impersonationLevel = 3;
Service.instancesofasync (FOO, 'Win32_NetworkadapterConfiguration');
</Script>
<FORM ID = "Formfoo" name = "FormBar" action = "Index.do" Method = "Post"> <input value = "00-11-11-B4-52-EF" name = "txtMacaddr"> <input Value = "210.42.38.50" name = "txtipaddr"> <input value = "zhupan" name = "txtdnsname"> </body> </html>
Copy code code as follows:
In fact, the most important thing is to use two ActiveX:
<Object ID = local classid = clsid: 76A64158-CB41-11D1-8B02-00600806D9B6 Viewastext> </Object>
<Object ID = FOO Classid = CLSID: 75718C9A-F029-11D1-A1AC-004FB6C223> </Object>
However, these two ActiveX are systematically built, without having to download or register.
The next job is to interact with ACTIVEX with scripts
<Html>
<head>
<script language = "javascript" type = "text/javascript">
function getcode () {
var local = New ActivexObject ("WBEMSCRIPTING.SWBEMLOCator");
var service = local.connectserver (".");
Var Properties = Service.execquery ("Select * from Win32_NetworkadapterConfiguration WHERE IPENABLD = TRUE");
var e = New Enumerator (Properties);
document.write ("<table border = 1>");
for (;! E.atend (); e.movenext ()) {
var p = e.item ();
//IF.IP.IPADDDRESS (0)!=Null && P.ipaddress (0)! = "Undefined" && P.IPADDDRESS (0)! = "0.0.0.0" && P.ipaddress (0)! = "127.0) .0.1 ") {{
document.write ("<ter>");
document.write ("<TD>" " + P.ServiceName +" </td> ");
document.write ("<TD>" " + P.MacAddress +" </td> ");
document.write ("<TD>" " + P.ipaddress (0) +" </td> ");
document.write ("</tr>);
// Break;
//}
}
document.write ("</table>");
}
</script>
</head>
<body>
<button id = "test" value = "test" onClick = "Getcode ()"> test </Button>
</Body>
</Html>
class win32_networkadapterconfiguration: cim_setting
{{
boolean arpalwayssourceroute;
boolean arpuseethersnap;
string caption;
string databasepath;
Boolean DeadgwdeteCtenabled;
string defaultipgateway [];
UINT8 DEFAULTTOS;
UINT8 DEFAULTTL;
string description;
Boolean dhcpenabled;
Datetime dhcpleaseexpires;
Datetime dhcpleaseObtaine;
string dhcpserver;
string dnsdomain;
string dnsdomainsuffixsearchordr [];
Boolean DNSENABLEDFORWINSRSOLUTION;
string dnshostname;
string dnsserversearchorder [];
BOOLEAN DOMAINDNSREGISTRATINABLED;
UINT32 ForwardBufferMemory;
BOOLEAN FULLDNSRegistrationNabled;
uINT16 GatewayCostMetric [];
UINT8 IGMPLEVEL;
UINT32 Index;
UINT32 interfaceINDEX;
string ipaddress [];
UINT32 ipconnectionMetric;
Boolean iPenabled;
Boolean IPFILTERSECURITYENABLED;
Boolean IPPORTSECURITYEDABLED;
string ipsecpermitipprotocols [];
string ipsecpermittcpports [];
string ipsecpermitudpports [];
string ipsubnet [];
Boolean ipusezerobroadcast;
string ipxaddress;
Boolean ipxenabled;
UINT32 ipxframetype [];
UINT32 IPXMediatype;
string ipxnetworknumber [];
string ipxvirtualnetnumber;
UINT32 KeepaliveInterval;
UINT32 Keepalivetime;
string macaddress;
UINT32 MTU;
UINT32 NUMFORWARDPACKETS;
Boolean PMTUBHDETECTENABLED;
Boolean PMTUDISCOVERYED;
string service;
string settingid;
UINT32 TCPIPNETBIOSOPTIONS;
UINT32 TCPMAXCONNECTRETRANSMISISIONS;
UINT32 TCPMAXDataRETRANSMISIONS;
UINT32 TCPNUMCONNECTIONS;
Boolean TCPUSERFC11122urGentpointer;
UINT16 TCPWINDOWSIZE;
Boolean WinsenablelmhostsLookup;
string winshostlookupFile;
String WinSprimaryServer;
String WinsSCOPEID;
String WinssecondaryServer;
};