MatthewKing / DeviceId

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.
MIT License
722 stars 118 forks source link

does not work on Windows 7 enterprise sp1 #56

Closed songjiefa closed 1 year ago

songjiefa commented 2 years ago

The Win7 OS only install .net 6 runtime, and my code reference DeviceId.Windows.Mmi. When I try to get device id, it throw error message as below, and I found the relate issue of mmi https://github.com/PowerShell/MMI/issues/43

Time:2022-06-01 11:50:32.6242 Software version: 1.0.0.0 Operating system information: Message: Microsoft.Management.Infrastructure.CimException: FAILED at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, String errorMessage, InstanceHandle errorData) at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, InstanceHandle errorData) at Microsoft.Management.Infrastructure.CimSession.Create(String computerName, CimSessionOptions sessionOptions) at DeviceId.Windows.Mmi.Components.MmiSystemDriveSerialNumberDeviceIdComponent.GetValue() at DeviceId.Formatters.HashDeviceIdFormatter.<>c.b__3_1(KeyValuePair2 x) at System.Linq.Enumerable.SelectIPartitionIterator2.PreallocatingToArray(Int32 count) at System.Linq.Enumerable.SelectIPartitionIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IDictionary2 components) at DeviceId.DeviceIdBuilder.ToString() at Microsoft.Practices.EnterpriseLibrary.Security.SerialKeyManager.GetDeviceId(String productName, String productVersion) at Omec.ResistanceCounter.ViewModels.Common.SerialNumberHelper.GetCurrentMachineSerialNumber(String productName, String productVersion) in C:\Projects\ResistanceCounter\Omec.ResistanceCounter\Omec.ResistanceCounter.ViewModels\Common\SerialNumberHelper.cs:line 28 at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, String errorMessage, InstanceHandle errorData) at Microsoft.Management.Infrastructure.CimException.ThrowIfMiResultFailure(MiResult result, InstanceHandle errorData) at Microsoft.Management.Infrastructure.CimSession.Create(String computerName, CimSessionOptions sessionOptions) at DeviceId.Windows.Mmi.Components.MmiSystemDriveSerialNumberDeviceIdComponent.GetValue() at DeviceId.Formatters.HashDeviceIdFormatter.<>c.<GetDeviceId>b__3_1(KeyValuePair2 x) at System.Linq.Enumerable.SelectIPartitionIterator2.PreallocatingToArray(Int32 count) at System.Linq.Enumerable.SelectIPartitionIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at DeviceId.Formatters.HashDeviceIdFormatter.GetDeviceId(IDictionary2 components) at DeviceId.DeviceIdBuilder.ToString() at Microsoft.Practices.EnterpriseLibrary.Security.SerialKeyManager.GetDeviceId(String productName, String productVersion) at Omec.ResistanceCounter.ViewModels.Common.SerialNumberHelper.GetCurrentMachineSerialNumber(String productName, String productVersion) in C:\Projects\ResistanceCounter\Omec.ResistanceCounter\Omec.ResistanceCounter.ViewModels\Common\SerialNumberHelper.cs:line 28

wagenheimer commented 2 years ago

I have the same problem.

System.IO.FileNotFoundException: Could not load file or assembly 'DeviceId, Version=6.2.0.0, Culture=neutral, PublicKeyToken=f755c371b5c59c52'.

greendimka commented 1 year ago

@songjiefa , @wagenheimer - can you specify the versions of DeviceId you use? Including versions of DeviceId.Windows.Mmi and .NET you use.

songjiefa commented 1 year ago

DeviceId.Windows.Mmi & DeviceId.Windows & DeviceId =>6.2.0.0 .net runtime => 6.0.1

MatthewKing commented 1 year ago

Can you use DeviceId.Windows.Wmi instead?

songjiefa commented 1 year ago

I use DeviceId.Windows.Wmi build WPF software with .net 6 runtime, it need package .net 6 runtime into my installer, and will throw above error in some windows 7 sp1 OS, which haven't install .net framework runtime, so I also need package .net framework 4.8 into my installer(and have to turn on .net framework 3.5) . This is weird.

MatthewKing commented 1 year ago

Ah yep, if you're installing on a system that doesn't have .NET Framework at all then you'll need MMI rather than WMI. That's as far as I can help you, though. If MMI isn't working on your (out of support) OS then you'll need to raise an issue there. Or use DeviceId features that don't rely on WMI/MMI.