node-machine-id icon indicating copy to clipboard operation
node-machine-id copied to clipboard

Access denied in Windows Electron

Open sr258 opened this issue 3 years ago • 5 comments

I use node-machine-id in an Electron app that is packages with ASAR.

I see users who can't get the machine ID in their app. My error log includes this message:

Error: Error while obtaining machine id: Error: Command failed: %windir%\System32\REG.exe QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid
Zugriff verweigert (= German for 'access denied')

    at ChildProcess.exithandler (node:child_process:406:12)
    at ChildPr...

I thought that the library doesn't use elevated rights. Is this specific to Electron? How can I work around this?

sr258 avatar Apr 29 '22 15:04 sr258

Hey what happened? Did you find a solution?

jrohlandt avatar Jan 25 '23 06:01 jrohlandt

No, I moved away from the library and generate a random id that I save in the user directory.

sr258 avatar Jan 25 '23 06:01 sr258

I ended up doing something similar. Thanks for the reply.

jrohlandt avatar Jan 26 '23 05:01 jrohlandt

We received the same error for one of our clients. They have laptops with policies that don't allow editing registry values:

Command failed: %windir%\System32\REG.exe QUERY HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography /v MachineGuid\nERROR: Registry editing has been disabled by your administrator.

So, we ended up with something like:

import { v4 as uuidv4 } from 'uuid';
import { machineId } from 'node-machine-id';

let machineUniqueId: string;
try {
  machineUniqueId = await machineId(true);
} catch (error) {
  machineUniqueId = uuidv4();
}

// save id later

ielektronick avatar Jan 27 '23 07:01 ielektronick

hii, I have created custom package which doesn't require admin privileges on windows, https://www.npmjs.com/package/node-machine-uid.

Alucard17 avatar Apr 12 '23 14:04 Alucard17