JavaScript 获取客户端计算机硬件及系统信息
通过WMI来实现获取客户端计算机硬件及系统信息:
代码实现主要包括这几部分:
-
- 先通过new ActiveXObject ("WbemScripting.SWbemLocator"); 访问到WbemScripting对象。
- 通过locator.ConnectServer(".");连接我们本地电脑(.代表本地电脑,当然
- 也可以访问其他计算机)。
- 通过service.ExecQuery("SELECT * FROM Win32_Processor")这个类似sql的语句(其实系统信息也是存储在计算中一个类似数据库的文件中)获取我们需要的对象的记录集。
- 通过new Enumerator来创建一个可枚举的对象,下面就可以遍历取信息了。
-
注意:运行的前提是要修改浏览器安全设置,“允许对未标记为可安全执行的ActiveX
脚本的运行”。这里主要取了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
示例:
1function button1_onclick() {//cpu 信息
2 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
3 var service = locator.ConnectServer(".");
4 var properties = service.ExecQuery("SELECT * FROM Win32_Processor");
5 var e = new Enumerator (properties);
6 document.write("");
");
7 for (;!e.atEnd();e.moveNext ())
8 {
9 var p = e.item ();
10 document.write(""); ");
11 document.write("" + p.Caption + " ");
12 document.write("" + p.DeviceID + " ");
13 document.write("" + p.Name + " ");
14 document.write("" + p.CpuStatus + " ");
15 document.write("" + p.Availability + " ");
16 document.write("" + p.Level + " ");
17 document.write("" + p.ProcessorID + " ");
18 document.write("" + p.SystemName + " ");
19 document.write("" + p.ProcessorType + " ");
20 document.write("
21 }
22 document.write("
23}
24
25function Button2_onclick() {//CD-ROM 信息
26 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
27 var service = locator.ConnectServer(".");
28 var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive");
29 var e = new Enumerator (properties);
30 document.write("");
");
31 for (;!e.atEnd();e.moveNext ())
32 {
33 var p = e.item ();
34 document.write(""); ");
35 document.write("" + p.Caption + " ");
36 document.write("" + p.Description + " ");
37 document.write("" + p.Drive + " ");
38 document.write("" + p.Status + " ");
39 document.write("" + p.MediaLoaded + " ");
40 document.write("
41 }
42 document.write("
43}
44
45function Button3_onclick() {//键盘信息
46 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
47 var service = locator.ConnectServer(".");
48 var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard");
49 var e = new Enumerator (properties);
50 document.write("");
");
51 for (;!e.atEnd();e.moveNext ())
52 {
53 var p = e.item ();
54 document.write(""); ");
55 document.write("" + p.Description + " ");
56 document.write("" + p.Name + " ");
57 document.write("" + p.Status + " ");
58 document.write("
59 }
60 document.write("
61}
62
63function Button4_onclick() {//主板信息
64 var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
65 var service = locator.ConnectServer(".");
66 var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard");
67 var e = new Enumerator (properties);
68 document.write("");
");
69 for (;!e.atEnd();e.moveNext ())
70 {
71 var p = e.item ();
72 document.write(""); ");
73 document.write("" + p.HostingBoard + " ");
74 document.write("" + p.Manufacturer + " ");
75 document.write("" + p.PoweredOn + " ");
76 document.write("" + p.Product + " ");
77 document.write("" + p.SerialNumber + " ");
78 document.write("" + p.Version + " ");
79 document.write("
80 }
81 document.write("
82}转自http://www.blogjava.net/redhatlinux/archive/2009/02/11/254254.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
