javascript 硬碟序號+其它硬體資訊

來源:互聯網
上載者:User

看了看別的資料有提取CPU,MAC的現成代碼卻沒有硬碟序號,找了好久才找到提取硬碟序號的參數。於是自己給補上了。
<html>
<head>
<title>提取硬碟序號</title>
<script>
function disk() {//硬碟序號 資訊
   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>");
   }
   document.write("</table>");
}
</script>
</head>
<body>
<input type="button" value="硬碟序號" onclick="disk()">
</body>
</html>

在這上找的代碼:
對於寫過ASP或.net 的人來說,通過asp或.net 語言來獲得用戶端的硬體資訊是很熟悉的.但如何通過javascript這種用戶端指令碼來獲得用戶端的資訊呢?請看以下執行個體:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
   <head>
      <title>javascript獲得用戶端硬體資訊-www.web2bar.cn/</title>
      <meta name="GENERATOR" content="Microsoft Visual Studio .NET
7.1">
      <meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
   <script id=clientEventHandlersJS language=javascript>
<!--
  
function Button2_onclick() {//CPU 資訊
   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_Processor");
   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.Caption + "</td>");
      document.write("<td>" + p.DeviceID + "</td>");
      document.write("<td>" + p.Name + "</td>");
      document.write("<td>" + p.CpuStatus + "</td>");
      document.write("<td>" + p.Availability + "</td>");
      document.write("<td>" + p.Level + "</td>");
      document.write("<td>" + p.ProcessorID + "</td>");
      document.write("<td>" + p.SystemName + "</td>");
      document.write("<td>" + p.ProcessorType + "</td>");
      document.write("</tr>");
   }
   document.write("</table>");
}
  
function Button1_onclick() {//磁碟片資訊
   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_FloppyDrive");
   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.Description + "</td>");
      document.write("<td>" + p.DeviceID + "</td>");
      document.write("<td>" + p.Status + "</td>");
      document.write("<td>" + p.Manufacuturer + "</td>");
      document.write("</tr>");
   }
   document.write("</table>");
}
  
function Button1_onclick() {//CD-ROM 資訊
   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_CDROMDrive");
   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.Caption + "</td>");
      document.write("<td>" + p.Description + "</td>");
      document.write("<td>" + p.Drive + "</td>");
      document.write("<td>" + p.Status + "</td>");
      document.write("<td>" + p.MediaLoaded + "</td>");
      document.write("</tr>");
   }
   document.write("</table>");
}
  
function Button1_onclick() {//鍵盤資訊
   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_Keyboard");
   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.Description + "</td>");
      document.write("<td>" + p.Name + "</td>");
      document.write("<td>" + p.Status + "</td>");
      document.write("</tr>");
   }
   document.write("</table>");
}
  
function Button1_onclick() {//主板資訊
   var locator = new ActiveXObject ("WbemScripting.SWbemLocator");
   var service = locator.ConnectServer(".");
   var properties = service.ExecQuery("SELECT * FROM Win32_BaseBoard");
   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.HostingBoard + "</td>");
      document.write("<td>" + p.Manufacturer + "</td>");
      document.write("<td>" + p.PoweredOn + "</td>");
      document.write("<td>" + p.Product + "</td>");
      document.write("<td>" + p.SerialNumber + "</td>");
      document.write("<td>" + p.Version + "</td>");
      document.write("</tr>");
   }
   document.write("</table>");
}
  
//-->
</script>
</head>
   <body>
      <INPUT id="Button1" type="button" value="Button"
name="Button1" language=javascript onclick="return Button1_onclick()">
   </body>
</html>
使用javascript方式獲得用戶端的資訊主要的優點是,不需求伺服器資源.不需求重新整理網頁.直接在用戶端執行指令碼獲得顯示.

在這上找到了硬碟序號的參數:
\'獲得硬碟序號
Dim cmicWmi As New System.Management.ManagementObjectSearcher(\"SELECT * FROM Win32_DiskDrive\")
Dim Uint32 As UInt32
For Each cmicWmiObj As ManagementObject In cmicWmi.Get
Uint32 = cmicWmiObj(\"signature\")
Next
TextBox1.Text = Uint32.ToString
和在一塊總算給提出來了,呵呵。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.