Showing posts with label cpu id. Show all posts
Showing posts with label cpu id. Show all posts

Thursday, January 21, 2010

Get Client CPU ID with Javascript

For whatever purpose it may serve, here's how to get the client CPU ID through javascript. Just a warning though, this script uses ActiveX object which is disabled by default on browsers and I'm not sure if you can enable it on non-IE. So for now we'll just do it with Internet Explorer.


Go to Tools then Internet Options.





Then on the Security tab click on "Custom Level..."





Go down until you see "Initialize and script ActiveX controls not marked as safe..." and enable it then click Ok.


Now we go to the scripting part. Add this next snippet in your html page.



<script type="text/javascript">
    var str = "";
    var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}");
    e = new Enumerator(wmi.InstancesOf("Win32_Processor"));
    for(; !e.atEnd(); e.moveNext()) {
        var s = e.item();
        str = s.ProcessorID;
    }
</script>


You can add the script above anywhere on your html head or body, but if you chose to put it on the body be sure to place it anywhere above this next snippet, which just displays the CPU ID in the page.


<b>Client CPU ID : </b><span id="spanCPUID" />

<script type="text/javascript">

    document.getElementById("spanCPUID").innerHTML = str;
</script>
                        


And that's it, you should now see the client computer's cpu id when you run the page.


-k