本来是想在网上找用Javascript获取打印机信息的方法,但是没想到找到了更多有用的信息,特此记录下来。
//系统信息获取 function getSysInfo(){ var locator = new ActiveXObject ("WbemScripting.SWbemLocator"); var service = locator.ConnectServer("."); //CPU信息 var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item(); var cpuType=cpu.Name,hostName=cpu.SystemName; //内存信息 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} //系统信息 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} }
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("<table border=1>"); for (; !e.atEnd(); e.moveNext ()) { var p = 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>"); } 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("<table border=1>"); for (; !e.atEnd(); e.moveNext ()) { var p = 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>"); } 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("<table border=1>"); for (; !e.atEnd(); e.moveNext ()) { var p = 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>"); } 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("<table border=1>"); for (; !e.atEnd(); e.moveNext ()) { var p = 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>"); }
//获取本机IP function GetLocalIPAddress(){ var obj = null; var rslt = ""; try { obj = new ActiveXObject("rcbdyctl.Setting"); rslt = obj.GetIPAddress; obj = null; } catch(e) { //异常发生 } //return rslt; alert(rslt) }