js获取系统信息
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);
var infoObj = document.getElementById("info");
var infoStr = "<table border=1>";
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
infoStr+="<tr><td>Caption-" + p.Caption + "</td></tr>";
infoStr+="<tr><td>DeviceID-" + p.DeviceID + "</td></tr>";
infoStr+="<tr><td>Name-" + p.Name + "</td></tr>";
infoStr+="<tr><td>CpuStatus-" + p.CpuStatus + "</td></tr>";
infoStr+="<tr><td>Availability-" + p.Availability + "</td></tr>";
infoStr+="<tr><td>Level-" + p.Level + "</td></tr>";
infoStr+="<tr><td>ProcessorID-" + p.ProcessorID + "</td></tr>";
infoStr+="<tr><td>SystemName-" + p.SystemName + "</td></tr>";
infoStr+="<tr><td>ProcessorType-" + p.ProcessorType + "</td></tr>";
infoStr+="<tr><td>Architecture-" + p.Architecture + "</td></tr>";
infoStr+="<tr><td>ConfigManagerErrorCode-" + p.ConfigManagerErrorCode + "</td></tr>";
}
infoStr += "</table>";
infoObj.innerHTML=infoStr;
}
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);
var infoObj = document.getElementById("info");
var infoStr = "<table border=1>";
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
infoStr+="<tr><td>Caption-" + p.Caption + "</td></tr>";
infoStr+="<tr><td>Description-" + p.Description + "</td></tr>";
infoStr+="<tr><td>Drive-" + p.Drive + "</td></tr>";
infoStr+="<tr><td>Status-" + p.Status + "</td></tr>";
infoStr+="<tr><td>MediaLoaded-" + p.MediaLoaded + "</td></tr>";
}
infoStr += "</table>";
infoObj.innerHTML=infoStr;
}
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);
var infoObj = document.getElementById("info");
var infoStr = "<table border=1>";
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
infoStr+="<tr>";
infoStr+="<td>Description " + p.Description + "</td>";
infoStr+="<td>Name " + p.Name + "</td>";
infoStr+="<td>Status " + p.Status + "</td>";
infoStr+="</tr>";
}
infoStr += "</table>";
infoObj.innerHTML=infoStr;
}
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);
var infoObj = document.getElementById("info");
var infoStr = "<table border=1>";
for (;!e.atEnd();e.moveNext ())
{
var p = e.item ();
infoStr+="<tr>";
infoStr+="<td>HostingBoard " + p.HostingBoard + "</td>";
infoStr+="<td>Manufacturer " + p.Manufacturer + "</td>";
infoStr+="<td>PoweredOn " + p.PoweredOn + "</td>";
infoStr+="<td>Product " + p.Product + "</td>";
infoStr+="<td>SerialNumber " + p.SerialNumber + "</td>";
infoStr+="<td>Version " + p.Version + "</td>";
infoStr+="</tr>";
}
infoStr += "</table>";
infoObj.innerHTML=infoStr;
}
</script>
<body>
<input type=button value='cpu 信息' onclick="button1_onclick()">
<input type=button value='CD-ROM 信息' onclick="Button2_onclick()">
<input type=button value='键盘信息' onclick="Button3_onclick()">
<input type=button value='主板信息' onclick="Button4_onclick()">
<div id=info>
...
</div>
</body>
这里主要取了CPU、内存及系统用户几个信息,大家利用WMI的API或者借助JSEDIT获取
到更多的信息。下面列出了常用信息的类:
Win32_Processor // CPU 处理器
Win32_PhysicalMemory // 物理内存
Win32_Keyboard // 键盘
Win32_PointingDevice // 点输入设备,如鼠标
Win32_DiskDrive // 硬盘驱动器
Win32_CDROMDrive // 光盘驱动器
Win32_BaseBoard // 主板
Win32_BIOS // BIOS 芯片
Win32_ParallelPort // 并口
Win32_SerialPort // 串口
Win32_SoundDevice // 多媒体设置
Win32_USBController // USB 控制器
Win32_NetworkAdapter // 网络适配器
Win32_NetworkAdapterConfiguration // 网络适配器设置
Win32_Printer // 打印机
Win32_PrinterConfiguration // 打印机设置
Win32_PrintJob // 打印机任务
Win32_TCPIPPrinterPort // 打印机端口
Win32_POTSModem // MODEM
Win32_POTSModemToSerialPort // MODEM 端口
Win32_DesktopMonitor // 显示器
Win32_VideoController // 显卡细节。
Win32_VideoSettings // 显卡支持的显示模式。
Win32_TimeZone // 时区
Win32_SystemDriver // 驱动程序
Win32_DiskPartition // 磁盘分区
Win32_LogicalDisk // 逻辑磁盘
Win32_LogicalMemoryConfiguration // 逻辑内存配置
Win32_PageFile // 系统页文件信息
Win32_PageFileSetting // 页文件设置
Win32_BootConfiguration // 系统启动配置
Win32_OperatingSystem // 操作系统信息
Win32_StartupCommand // 系统自动启动程序
Win32_Service // 系统安装的服务
Win32_Group // 系统管理组
Win32_GroupUser // 系统组帐号
Win32_UserAccount // 用户帐号
Win32_Process // 系统进程
Win32_Thread // 系统线程
Win32_Share // 共享
Win32_NetworkClient // 已安装的网络客户端
Win32_NetworkProtocol // 已安装的网络协议
WMI Win32类的完整信息及详细列表请参考MSDN:
http://msdn2.microsoft.com/en-us/library/aa394084(VS.85).aspx