怎样用JS获取客户端的硬件,系统等信息

JavaScript08

怎样用JS获取客户端的硬件,系统等信息,第1张

通过WMI来实现获取客户端计算机硬件及系统信息:

1//系统信息获取

2function 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}

获取系统当前小时展示不同的时间状态

data(){

return{

sayHello:undefined

}}

constnow=newDate()

consthour=now.getHours()

if(hour<6) {

this.sayHello='凌晨好'

}elseif(hour<9) {

this.sayHello='早上好'

}elseif(hour<12) {

this.sayHello='上午好'

}elseif(hour<14) {

this.sayHello='中午好'

}elseif(hour<17) {

this.sayHello='下午好'

}elseif(hour<19) {

this.sayHello='傍晚好'

}elseif(hour<22) {

this.sayHello='晚上好'

}else{

this.sayHello='夜里好'

}

},