denisbrodbeck / machineid

Get the unique machine id of any host (without admin privileges)
MIT License
1k stars 143 forks source link

Error while getting machine id in Windows 10 #2

Closed shahidhk closed 6 years ago

shahidhk commented 6 years ago

Even though the mentioned key exists in registry, the following error is thrown while accessing the machineid:

error: machineid: machineid: The system cannot find the file specified

Windows 10 Pro Version: 1709 Build: 16299.125

Any clues on debugging this?

machineguid

denisbrodbeck commented 6 years ago

Sorry for late response, holiday season :smile:

That's kind of strange. Do you have a gist or minimal repo, where I could reproduce your issue?

You could use delve to drill into this with a debugger, or maybe modify the source to panic within id_windows.go.

You should be able to test the library by cd'ing into GOSRC\src\github.com\denisbrodbeck\machineid and running go test ./....

shahidhk commented 6 years ago

No probs. 😃

The error was reported by some of our users. We were unable to reproduce this with our test machines. Anyway, I will try to get the user to introduce panic, run the tests and get back to you.

MikeFair commented 6 years ago

I get the same error on a Windows 7 Home Premium laptop

MikeFair commented 6 years ago

Turns out the "HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography" Key itself exists but doesn't seem to contain any values (or I just don't have permissions to see those values (even as an administrator)). All the values in that subtree appear blank on this machine.

This means the "MachineGuid" value is not found or truly isn't there.

Per this msdn post: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d617a579-278d-4e77-812e-99fa68135d0d/windows-installation-guid?forum=windowscompatibility

They say MachineGUID is not necessarily Unique (but they were also talking specifically about system reinstalls from backups and OS reinstalls)

They suggested the assembly: System.Identity.UniqueID, Not sure if this correlates to a RegKey anywhere.

They also point to a discussion that says take CPUID + HD VOLUME SERIAL NUMBER [ + more hw id] https://stackoverflow.com/questions/3474940/unique-computer-id

And https://www.nextofwindows.com/the-best-way-to-uniquely-identify-a-windows-machine mentions the Windows ProductId / SerialId from the Activation (perhaps there's something else from the Activation process) ; though this is likely a problem for unactivated Windows machines...

Here's a link on what goes into the ProductId: https://technet.microsoft.com/en-us/library/bb457054.aspx#EEAA

denisbrodbeck commented 6 years ago

@MikeFair Thanks for your comment.

Just let me give my two cents 😄

Turns out the "HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography" Key itself exists but doesn't seem to contain any values (or I just don't have permissions to see those values (even as an administrator)).

You are getting this strange empty view, because you're looking at the wrong registry node. The real key is always within HKLM\SOFTWARE\Microsoft\Cryptography. Some keys are x86 only, some keys are x64 only and some of them are shared. Everything below Wow6432Node would be your exclusive view into the x86 registry, where only apps live, which do not support x64 (as far I remember). Simetimes it's really confusing, because both HKLM\SOFTWARE\Wow6432Node\Microsoft\Cryptography and HKLM\SOFTWARE\Microsoft\Cryptography exist on a x64 system.

They suggested the assembly: System.Identity.UniqueID

I know of this thread, but I've never managed to get hold of that specific value. Information on google is +very+ sparse. I've tried to fetch that value with C#, but never found the specific assembly to get that variable from 😕

They also point to a discussion that says take CPUID + HD VOLUME SERIAL NUMBER

I've visited that thread before creating this library. One takeaway is that CPUID is not unique. At least, not since the last ~10 years. Intel deactivated that feature long ago. Usually some zero-ed string is returned, when someone tries to read the specific variable.

Using the SN of the HD volume actually works, though when testing it on various systems, I've sometimes needed more privileges, so I stopped pursuing that path. It fails when running from (Linux) Live-OS.

And https://www.nextofwindows.com/the-best-way-to-uniquely-identify-a-windows-machine mentions the Windows ProductId / SerialId from the Activation

That works, too. There are probably caveats when using the ProductID, while windows is still not activated, and possibly more issues when the os got activated (some weeks later). Does the ID change? What happens on hardware changes? What happens when the user upgrades from Windows 7 Home to Windows 7 Pro?

In the end I turned to MachineGuid because that seemed to be the most stable and universally available identifier I could find 😃

denisbrodbeck commented 6 years ago

@shahidhk @MikeFair I think I've found the issue.

If one creates a x86 app and runs that app on a x64 windows, the error is triggered. Fixing it now.

denisbrodbeck commented 6 years ago

@shahidhk @MikeFair In my testing the issue has been fixed. If there' s still an issue, feel free to reopen this issue.

MikeFair commented 6 years ago

Just did: go get -u github.com\denisbrodbeck\machineid go install github.com\denisbrodbeck\machineid\cmd\machineid

And all is well! :) Awesome work!

shahidhk commented 6 years ago

Thanks @denisbrodbeck