u011954277
小菜来袭
采纳率74%
2015-11-20 02:13 阅读 2.7k

js 如何获取硬盘序列号呢?找了很久没找到合适的

  var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive");
   var e = new Enumerator (properties);
   document.write("<table border=1>");
   for (;!e.atEnd();e.moveNext ())
   {
      var p = e.item ();
      document.write("<tr>");
      document.write("<td>" + p.signature + "</td>");
      document.write("</tr>");
   }

网上大部分是这样写的 但是获取的不对 大部分台式机根本获取不到 大家有什么好办法吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    showbo GoCityPass新加坡曼谷通票 2015-11-20 02:50
    
        var locator = new ActiveXObject("WbemScripting.SWbemLocator");
        var service = locator.ConnectServer(".");
        var properties = service.ExecQuery("SELECT * FROM Win32_PhysicalMedia");
        var e = new Enumerator(properties);
        document.write("<table border=1>");
        for (; !e.atEnd() ; e.moveNext()) {
            var p = e.item();
            if (p.SerialNumber) {
                document.write("<tr>");
                document.write("<td>" + p.SerialNumber + "</td>");
                document.write("</tr>");
            }
        }
    
    点赞 评论 复制链接分享
  • h_yuchen Houser辰 2015-11-20 03:46

    //注意 在 IE浏览器下打开 ActiveXObject 兼容

    window.onload = function(){
    var info = JSON.stringify(getSysInfo());
    alert(info);
    }

    function getSysInfo(){
    var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
    var service = locator.ConnectServer(".");
    //CPU信息
    var cpu = new Enumerator (service.ExecQuery("SELECT * FROM Win32_Processor")).item();
    var cpuType=cpu.Name,hostName=cpu.SystemName;
    //内存信息
    var memory = new Enumerator (service.ExecQuery("SELECT * FROM Win32_PhysicalMemory"));
    for (var mem=[],i=0;!memory.atEnd();memory.moveNext()) mem[i++]={cap:memory.item().Capacity/1024/1024,speed:memory.item().Speed}
    //系统信息
    var system=new Enumerator (service.ExecQuery("SELECT * FROM Win32_ComputerSystem")).item();
    var physicMenCap=Math.ceil(system.TotalPhysicalMemory/1024/1024),curUser=system.UserName,cpuCount=system.NumberOfProcessors

    var properties = service.ExecQuery("SELECT * FROM Win32_DiskDrive");
    

      var p = new Enumerator (properties).item();
    return {cpuType:cpuType,cpuCount:cpuCount,hostName:hostName,curUser:curUser,memCap:physicMenCap,mem:mem,num:p.signature }
    }

    点赞 1 评论 复制链接分享

相关推荐