怎样用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}
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}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
万企明道
2024-08-07 广告
2024-08-07 广告
低代码开发系统,作为上海万企明道软件有限公司的重要产品方向,极大地简化了软件开发流程。它允许非专业开发者通过图形化界面与少量代码,快速构建应用程序。这一系统降低了技术门槛,加速了项目上线时间,同时提升了软件的灵活性和可维护性。我们致力于为用...
点击进入详情页
本回答由万企明道提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询