Obtaining client hard disk numbers through JavaScript and applets

Source: Internet
Author: User

Only with JS implementation, for ie10+ browser

<script>

function Getserialnumber () {

var retVal = "";

var locator = new ActiveXObject ("WbemScripting.SWbemLocator");

var service = Locator. ConnectServer (".");

var properties = Service. ExecQuery ("SELECT * from win32_diskdrive");

var enu = new Enumerator (properties);

for (;! Enu.atend (); Enu.movenext ()) {

var p = Enu.item ();

if (retval!= ') {

RetVal + = ",";

}

RetVal + = P.serialnumber;

}

return retVal;

}

document.write ("Hard disk Number:" +getserialnumber ());

</script>

//************************************************************************************************************

Javaapplet implementation:

Import Java.applet.Applet;

Import Java.awt.Graphics;

Import java.io.IOException;

Import Java.util.Scanner;


public class Helloapplet extends Applet {

Private static final long serialversionuid = 5511892956119084309L;

@Override

public void Paint (Graphics g) {

g.DrawString (Getdriveserialnumber (), 10, 10);

}

Public String Getdriveserialnumber() {

String retvalue = "";

try {

Process process = Runtime.getruntime (). EXEC ("WMIC diskdrive get SerialNumber");

try {

Process.waitfor ();

} catch (Interruptedexception e) {

//

}

Scanner Scanner = new Scanner (Process.getinputstream ());

while (Scanner.hasnext ()) {

String line = Scanner.next ();

if ("SerialNumber". Equals (line)) {

Continue

}

if (retvalue.length () > 0) {

RetValue + = ",";

}

RetValue + = line;

}

Scanner.close ();

if (retvalue.length () = = 0) {

RetValue = "Failed to get SerialNumber";

}

} catch (IOException e) {

E.printstacktrace ();

RetValue = "Error:" + e.getmessage ();

}

return retvalue;

}

}

===========================html part

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>

<title>example of Serialnumber-applet.</title>

<body>

<object classid= "CLSID:CAFEEFAC-0016-0000-FFFF-ABCDEFFEDCBA"

type= "Application/x-java-applet" name= "Diskserialnumber"

style= "Position:absolute; Top: -1000px; Left: -1000px; " >

<param name= "code" value= "helloapplet " >

<param name= "archive" value= "Final.jar" >

<param name= "Mayscript" value= "true" >

<param name= "scriptable" value= "true" >

<param name= "width" value= "0" >

<param name= "height" value= "0" >

</object>


<script type= "Text/javascript" >

if (typeof (document.diskSerialNumber.isActive) = = "undefined") {

document.write ("Unable to detect serialnumber.");

} else {

var serialnumber = document. Diskserialnumber. Getdriveserialnumber ();

if (serialnumber.length > 0) {

document.write ("HDD: <br/>");

document.write ("

document.write (serialnumber);

}

}

</script>

</body>


Applet signature

Refer to: http://my.oschina.net/u/204292/blog/403337

JS and applet interaction can be consulted: http://my.oschina.net/penngo/blog/112513

Obtaining client hard disk numbers through JavaScript and applets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.