看了看別的資料有提取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
和在一塊總算給提出來了,呵呵。