Nw.js: How can I get the computer's unique id based on hardware info?

Created on 10 Apr 2013  路  14Comments  路  Source: nwjs/nw.js

How can I get the computer's unique id based on hardware info?

like CPU serial or Hard Disk?

Most helpful comment

@bruno-preti if you are using windows operating system, following code may help you to get HDD and CPU serial number

var sys = require('util')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
    console.log(stdout)
}

exec("wmic CPU get ProcessorId", puts);
exec("wmic DISKDRIVE get SerialNumber", puts);

All 14 comments

Have a look at the contents of the 'process' variable to get a bunch of unique information on the environment, you could try using some of this to construct a string and hash it to create a unique ID of your own.

But 'process' variable has some platform and runtime info, but no computer hardware id info.

How about something like this? https://npmjs.org/package/getmac

Sure, I use command line to get Mac address in java too. But It's hard to get CPU or Hard Disk serial in this way.

Okay, well you said you wanted a Unique ID - Mac Address should suffice for this purpose, if you actually just want to get the Hard Disk serial then that's probably a different question. You'll likely have to use exec to access it from the terminal but then your app won't be platform agnostic, there is no API exposed for this in the project.

What if the mac is not available or you can not rely on it because you're working on an app that runs in computers that don't have a network card?
I have the same issue of @linb and I need the ID of the HDD or CPU or something that you know it's there and won't be easily changed.

@bruno-preti if you are using windows operating system, following code may help you to get HDD and CPU serial number

var sys = require('util')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) {
    console.log(stdout)
}

exec("wmic CPU get ProcessorId", puts);
exec("wmic DISKDRIVE get SerialNumber", puts);

Thank you very much @srehanuddin ! I'll try with this if I'm required to do this again.
Have a nice day!

@srehanuddin your answer is very much helpful to get hdd serial number. But I want to save this serial number to a variable. So, I want its value. If I try to console.log(stdout.SerialNumber) then it gives me undefined

Perhaps the fingerprintjs2 is one of the solutions for this issue:

http://valve.github.io/fingerprintjs2/
https://github.com/Valve/fingerprintjs2

Browser allows very limited access to hardware. If you want to uniquely identify your clients, you can use the below chrome extension.

https://github.com/Antony007/ADNIdentifier

hi everyone. everyone for me asks about getting the device id of a computer from browser to send the access token between domain another, single sign-on. thank so much

Perhaps the fingerprintjs2 is one of the solutions for this issue:

http://valve.github.io/fingerprintjs2/
https://github.com/Valve/fingerprintjs2

Not unique on every browser.

As mentioned above, on Windows you can use wmic to check the hard drive serial number, but you can also check the motherboard serial number which is less likely to change. wmic bios get serialnumber

try {
  const execSync = require('child_process').execSync;
  const response = execSync('wmic bios get serialnumber');
  const serial = String(response).split('\n')[1];
  console.log(serial);
} catch (err) {
  console.log('Error getting serial number', err);
}
Was this page helpful?
0 / 5 - 0 ratings