1
//
系统信息获取
2 function getSysInfo(){
3 var locator = new ActiveXObject ( " WbemScripting.SWbemLocator " );
4 var service = locator.ConnectServer( " . " );
5 // CPU信息
6 var cpu = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_Processor " )).item();
7 var cpuType = cpu.Name,hostName = cpu.SystemName;
8 // 内存信息
9 var memory = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_PhysicalMemory " ));
10 for ( var mem = [],i = 0 ; ! memory.atEnd(); memory.moveNext()) mem[i ++ ] = {cap:memory.item().Capacity / 1024 / 1024 ,speed:memory.item().Speed}
11 // 系统信息
12 var system = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_ComputerSystem " )).item();
13 var physicMenCap = Math.ceil(system.TotalPhysicalMemory / 1024 / 1024 ),curUser = system.UserName,cpuCount = system.NumberOfProcessors
14
15 return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem}
16 }
2 function getSysInfo(){
3 var locator = new ActiveXObject ( " WbemScripting.SWbemLocator " );
4 var service = locator.ConnectServer( " . " );
5 // CPU信息
6 var cpu = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_Processor " )).item();
7 var cpuType = cpu.Name,hostName = cpu.SystemName;
8 // 内存信息
9 var memory = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_PhysicalMemory " ));
10 for ( var mem = [],i = 0 ; ! memory.atEnd(); memory.moveNext()) mem[i ++ ] = {cap:memory.item().Capacity / 1024 / 1024 ,speed:memory.item().Speed}
11 // 系统信息
12 var system = new Enumerator (service.ExecQuery( " SELECT * FROM Win32_ComputerSystem " )).item();
13 var physicMenCap = Math.ceil(system.TotalPhysicalMemory / 1024 / 1024 ),curUser = system.UserName,cpuCount = system.NumberOfProcessors
14
15 return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem}
16 }
其中"."代表本机,当然也能设其它机器。