node-machine-id
node-machine-id copied to clipboard
Access denied in Windows Electron
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?
Hey what happened? Did you find a solution?
No, I moved away from the library and generate a random id that I save in the user directory.
I ended up doing something similar. Thanks for the reply.
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
hii, I have created custom package which doesn't require admin privileges on windows, https://www.npmjs.com/package/node-machine-uid.