JS获取计算机信息

匆匆过客 提交于 2019-12-19 02:46:47

JS获取计算机信息

使用js获取计算机信息需要以下条件:

  1. 使用IE浏览器(需要使用到只有IE浏览器有的ActiveX控件)
  2. 允许ActiveX控件的运行
  3. 用WMI(微软开放的API接口,供脚本语言使用)
  4. 示例代码(使用时替换properties的查询参数):
<!DOCTYPE html>
<html lang="en">
	 <head>    
	  <meta charset="UTF-8">   
	  <meta name="viewport" content="width=device-width, initial-scale=1.0">    
	  <meta http-equiv="X-UA-Compatible" content="ie=edge">    <title>Document</title>
	 </head>
 <body>        
	  <script type="text/javascript">
		   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");        var service = locator.ConnectServer(".");       
		    var properties = service.ExecQuery("SELECT * FROM Win32_UserAccount");        
		    var e = new Enumerator (properties);       
		    document.write("<table border=1>");
		    /* Win32_UserAccount  //用户帐号     
		    for (;!e.atEnd();e.moveNext ()){                    
			     var p = e.item ();                          
			     document.write("<tr><td > " + ":" + p.AccountType + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.Caption + "</td></tr>");                   
			    document.write("<tr><td > " + ":" + p.Description + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.Disabled + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.Domain + "</td></tr>");                    
			    document.write("<tr><td > " + ":" + p.FullName + "</td></tr>");
			    document.write("<tr><td > " + ":" + p.InstallDate + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.LocalAccount + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.Lockout + "</td></tr>");                   
			    document.write("<tr><td > " + ":" + p.Name + "</td></tr>");                  
			    document.write("<tr><td > " + ":" + p.PasswordChangeable + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.PasswordExpires + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.PasswordRequired + "</td></tr>"); 
			    document.write("<tr><td > " + ":" + p.SID + "</td></tr>");                   
			    document.write("<tr><td > " + ":" + p.SIDType + "</td></tr>");  
			    document.write("<tr><td > " + ":" + p.Status + "</td></tr>");            
		   }       
		   */
		   
		    /* Win32_Service  //系统安装的服务
		    for (;!e.atEnd();e.moveNext ()){  
			     var p = e.item (); 
			     document.write("<tr><td></td> "); 
			     document.write(" <td>" + p.AcceptPause + "</td> ");
			     document.write(" <td>" + p.AcceptStop + "</td> ");
			     document.write(" <td>" + p.Caption + "</td> ");
			     document.write(" <td>" + p.CheckPoint + "</td> "); 
			     document.write(" <td>" + p.CreationClassName + "</td> ");
			     document.write(" <td>" + p.Description + "</td> ");
			     document.write(" <td>" + p.DesktopInteract + "</td> ");
			     document.write(" <td>" + p.DisplayName + "</td> ");
			     document.write(" <td>" + p.ErrorControl + "</td> ");
			     document.write(" <td>" + p.ExitCode + "</td> ");
			     document.write(" <td>" + p.InstallDate + "</td> ");
			     document.write(" <td>" + p.Name + "</td> ");
			     document.write(" <td>" + p.PathName + "</td> ");
			     document.write(" <td>" + p.ProcessId + "</td> ");
			     document.write(" <td>" + p.ServiceSpecificExitCode + "</td> ");
			     document.write(" <td>" + p.ServiceType + "</td> ");
			     document.write(" <td>" + p.Started + "</td> ");
			     document.write(" <td>" + p.StartMode + "</td> ");
			     document.write(" <td>" + p.StartName + "</td> ");
			     document.write(" <td>" + p.State + "</td> ");
			     document.write(" <td>" + p.Status + "</td> ");
			     document.write(" <td>" + p.SystemCreationClassName + "</td> ");
			     document.write(" <td>" + p.SystemName + "</td> ");
			     document.write(" <td>" + p.TagId + "</td> ");
			     document.write(" <td>" + p.WaitHint + "</td></tr>");
		    }        
		    */
		    
		    /* Win32_Group  //系统管理组
		    for (;!e.atEnd();e.moveNext ()){
			     var p = e.item ();
			     document.write("<tr><td></td>");
			     document.write("<td>" + p.Caption + "</td>");
			     document.write("<td>" + p.Description + "</td>");
			     document.write("<td>" + p.Domain + "</td>");
			     document.write("<td>" + p.InstallDate + "</td>"); 
			     document.write("<td>" + p.LocalAccount + "</td>");
			     document.write("<td>" + p.Name + "</td>");
			     document.write("<td>" + p.SID + "</td>");
			     document.write("<td>" + p.SIDType + "</td>");
			     document.write("<td>" + p.Status + "</td></tr>");
		    }
		    */
		    
		     /* Win32_UserAccount  //用户账号
		     for (;!e.atEnd();e.moveNext ()){
			      var p = e.item ();
			      document.write("<tr><td > " + p.AccountType + "</td></tr>");
			      document.write("<tr><td > " + p.Caption + "</td></tr>");
			      document.write("<tr><td > " + p.Description + "</td></tr>");
			      document.write("<tr><td > " + p.Disabled + "</td></tr>");
			      document.write("<tr><td > " + p.Domain + "</td></tr>");
			      document.write("<tr><td > " + p.FullName + "</td></tr>");
			      document.write("<tr><td > " + p.InstallDate + "</td></tr>");
			      document.write("<tr><td > " + p.LocalAccount + "</td></tr>");
			      document.write("<tr><td > " + p.Lockout + "</td></tr>");
			      document.write("<tr><td > " + p.Name + "</td></tr>");
			      document.write("<tr><td > " + p.PasswordChangeable + "</td></tr>");
			      document.write("<tr><td > " + p.PasswordExpires + "</td></tr>");
			      document.write("<tr><td > " + p.PasswordRequired + "</td></tr>");
			      document.write("<tr><td > " + p.SID + "</td></tr>");
			      document.write("<tr><td > " + p.SIDType + "</td></tr>");
			      document.write("<tr><td > " + p.Status + "</td></tr>");
		     }
		     */
		    
		     /* Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE
		     //网络适配器设置
		     for (;!e.atEnd();e.moveNext ()){
			      var p = e.item ();
			      document.write("<tr><td >MAC地址:" + p.MACAddress + "</td></tr>");
			      document.write("<tr><td >IP地址:" + p.IPAddress(0) + "</td></tr>");
		     } 
		     */
		     
		     /* Win32_BaseBoard  //主板
		     for (;!e.atEnd();e.moveNext ()) {
			      var p = e.item ();
			      document.write("<tr><td >主板ID:" + p.SerialNumber + "</td></tr>");
			      document.write("<tr><td >" + p.HostingBoard + "</td></tr>");
			      document.write("<tr><td >制造商:" + p.Manufacturer + "</td></tr>");
			      document.write("<tr><td >是否开启:" + p.PoweredOn + "</td></tr>");
			      document.write("<tr><td >型号:" + p.Product + "</td></tr>");
			      document.write("<tr><td >版本:" + p.Version + "</td></tr>");
		     }
		     */
		            
		     /* Win32_Processor  //CPU处理器
		     for (;!e.atEnd();e.moveNext ()) {
			      var p = e.item ();
			      document.write("<tr><td >CPU序列号:" + p.ProcessorID + "</td></tr>");
			      document.write("<tr><td >"+p.Caption+"</td></tr>");
			      document.write("<tr><td >CPU编号:"+p.DeviceID+"</td></tr>");
			      document.write("<tr><td >CPU型号:" + p.Name + "</td></tr>");
			      document.write("<tr><td >CPU状态:" + p.CpuStatus + "</td></tr>");
			      document.write("<tr><td >CPU可用性:" + p.Availability + "</td></tr>");
			      document.write("<tr><td >CUP Level:" + p.Level + "</td></tr>");
			      document.write("<tr><td >主机名称:" + p.SystemName + "</td></tr>");
			      document.write("<tr><td >Processor Type:" + p.ProcessorType + "</td></tr>");
		     }
		     */
		    
		    /* Win32_OperatingSystem  /操作系统信息
		    for (;!e.atEnd();e.moveNext ())      {
			     var p = e.item ();            
			     document.write("<tr><td > " + p.BootDevice + "</td></tr>");
			     document.write("<tr><td>" + p.BuildNumber + "</td></tr>");
			     document.write("<tr><td>" + p.BuildType + "</td></tr>");
			     document.write("<tr><td>" + p.Caption + "</td></tr>");
			     document.write("<tr><td>" + p.CodeSet + "</td></tr>");
			     document.write("<tr><td>" + p.CountryCode + "</td></tr>");
			     document.write("<tr><td>" + p.CreationClassName + "</td></tr>");
			     document.write("<tr><td>" + p.CSCreationClassName + "</td></tr>");
			     document.write("<tr><td>" + p.CSDVersion + "</td></tr>");
			     document.write("<tr><td>" + p.CSName + "</td></tr>");
			     document.write("<tr><td>" + p.CurrentTimeZone + "</td></tr>");
			     document.write("<tr><td>" + p.DataExecutionPrevention_Available + "</td></tr>");
			     document.write("<tr><td>" + p.DataExecutionPrevention_32BitApplications + "</td></tr>");
			     document.write("<tr><td>" + p.DataExecutionPrevention_Drivers + "</td></tr>");
			     document.write("<tr><td>" + p.DataExecutionPrevention_SupportPolicy + "</td></tr>");
			     document.write("<tr><td>" + p.Debug + "</td></tr>");
			     document.write("<tr><td>" + p.Description + "</td></tr>");
			     document.write("<tr><td>" + p.Distributed + "</td></tr>");
			     document.write("<tr><td>" + p.EncryptionLevel + "</td></tr>");
			     document.write("<tr><td>" + p.ForegroundApplicationBoost + "</td></tr>");
			     document.write("<tr><td>" + p.FreePhysicalMemory + "</td></tr>");
			     document.write("<tr><td>" + p.FreeSpaceInPagingFiles + "</td></tr>");
			     document.write("<tr><td>" + p.FreeVirtualMemory + "</td></tr>");
			     document.write("<tr><td>" + p.InstallDate + "</td></tr>");
			     document.write("<tr><td>" + p.LargeSystemCache + "</td></tr>");
			     document.write("<tr><td>" + p.LastBootUpTime + "</td></tr>");
			     document.write("<tr><td>" + p.LocalDateTime + "</td></tr>");
			     document.write("<tr><td>" + p.Locale + "</td></tr>");
			     document.write("<tr><td>" + p.Manufacturer + "</td></tr>");
			     document.write("<tr><td>" + p.MaxNumberOfProcesses + "</td></tr>");
			     document.write("<tr><td>" + p.MaxProcessMemorySize + "</td></tr>");
			     document.write("<tr><td>" + p.Name + "</td></tr>");
			     document.write("<tr><td>" + p.NumberOfLicensedUsers + "</td></tr>");
			     document.write("<tr><td>" + p.NumberOfProcesses + "</td></tr>");
			     document.write("<tr><td>" + p.NumberOfUsers + "</td></tr>");
			     document.write("<tr><td>" + p.OperatingSystemSKU + "</td></tr>");
			     document.write("<tr><td>" + p.Organization + "</td></tr>");
			     document.write("<tr><td>" + p.OSArchitecture + "</td></tr>");
			     document.write("<tr><td>" + p.OSLanguage + "</td></tr>");
			     document.write("<tr><td>" + p.OSProductSuite + "</td></tr>");
			     document.write("<tr><td>" + p.OSType + "</td></tr>");
			     document.write("<tr><td>" + p.OtherTypeDescription + "</td></tr>");
			     document.write("<tr><td>" + p.PAEEnabled + "</td></tr>");
			     document.write("<tr><td>" + p.PlusProductID + "</td></tr>");
			     document.write("<tr><td>" + p.PlusVersionNumber + "</td></tr>");
			     document.write("<tr><td>" + p.PortableOperatingSystem + "</td></tr>");
			     document.write("<tr><td>" + p.Primary + "</td></tr>");
			     document.write("<tr><td>" + p.ProductType + "</td></tr>");
			     document.write("<tr><td>" + p.RegisteredUser + "</td></tr>");
			     document.write("<tr><td>" + p.SerialNumber + "</td></tr>");
			     document.write("<tr><td>" + p.ServicePackMajorVersion + "</td></tr>");
			     document.write("<tr><td>" + p.ServicePackMinorVersion + "</td></tr>");
			     document.write("<tr><td>" + p.SizeStoredInPagingFiles + "</td></tr>");
			     document.write("<tr><td>" + p.Status + "</td></tr>");
			     document.write("<tr><td>" + p.SuiteMask + "</td></tr>");
			     document.write("<tr><td>" + p.SystemDevice + "</td></tr>");
			     document.write("<tr><td>" + p.SystemDirectory + "</td></tr>");
			     document.write("<tr><td>" + p.SystemDrive + "</td></tr>");
			     document.write("<tr><td>" + p.TotalSwapSpaceSize + "</td></tr>");
			     document.write("<tr><td>" + p.TotalVirtualMemorySize + "</td></tr>");
			     document.write("<tr><td>" + p.TotalVisibleMemorySize + "</td></tr>");
			     document.write("<tr><td>" + p.Version + "</td></tr>");
		     }
		     */
	   	document.write("</table>");
	   </script> 
 </body>
 </html>
  1. win32参数参考:

    Win32_BaseBoard // 主板

    Win32_BIOS // BIOS 芯片

    Win32_BootConfiguration // 系统启动配置

    Win32_CDROMDrive // 光盘驱动器

    Win32_DesktopMonitor // 显示器

    Win32_DiskDrive // 硬盘驱动器

    Win32_DiskPartition // 磁盘分区

    Win32_Group // 系统管理组

    Win32_GroupUser // 系统组帐号

    Win32_Keyboard // 键盘

    Win32_LogicalDisk // 逻辑磁盘

    Win32_LogicalMemoryConfiguration // 逻辑内存配置

    Win32_NetworkAdapter // 网络适配器

    Win32_NetworkAdapterConfiguration // 网络适配器设置

    Win32_NetworkClient // 已安装的网络客户端

    Win32_NetworkProtocol // 已安装的网络协议

    Win32_OperatingSystem // 操作系统信息

    Win32_PageFile // 系统页文件信息

    Win32_PageFileSetting // 页文件设置

    Win32_ParallelPort // 并口

    Win32_PhysicalMemory // 物理内存

    Win32_PointingDevice // 点输入设备,如鼠标

    Win32_POTSModem // MODEM

    Win32_POTSModemToSerialPort // MODEM 端口

    Win32_Printer // 打印机

    Win32_PrinterConfiguration // 打印机设置

    Win32_PrintJob // 打印机任务

    Win32_Process // 系统进程

    Win32_Processor // CPU 处理器

    Win32_SerialPort // 串口

    Win32_Service // 系统安装的服务

    Win32_Share // 共享

    Win32_SoundDevice // 多媒体设置

    Win32_StartupCommand // 系统自动启动程序

    Win32_SystemDriver // 驱动程序

    Win32_TCPIPPrinterPort // 打印机端口

    Win32_Thread // 系统线程

    Win32_TimeZone // 时区

    Win32_USBController // USB 控制器

    Win32_UserAccount // 用户帐号

    Win32_VideoController // 显卡细节

    Win32_VideoSettings // 显卡支持的显示模式

  2. 更多WMI信息参考:WMI官方链接

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!