-
Notifications
You must be signed in to change notification settings - Fork 126
Description
I am using v5.3 of the library (a bit old, but I haven't fully tested the new version).
I have the following for generating an unique id for each user:
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
try
{
return new DeviceIdBuilder()
.AddProcessorId()
.AddComponent(new CDriveSerialNumber())
.ToString();
}
catch
{
return new DeviceIdBuilder()
.AddProcessorId()
.AddSystemDriveSerialNumber()
.ToString();
}
}
public class CDriveSerialNumber : IDeviceIdComponent
{
public string Name { get; } = "CDriveSerialNumber";
public string GetValue()
{
using (var mo = new ManagementObject("win32_logicaldisk.deviceid=\"C:\""))
{
return mo["VolumeSerialNumber"].ToString();
}
}
}I have some exception telemetry set up and every once in a while, I saw the following:
System.UnauthorizedAccessException: Access is denied. (0x80070005 (E_ACCESSDENIED))
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementScope.InitializeGuts(Object o)
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObject.Initialize(Boolean getObject)
at System.Management.ManagementBaseObject.get_Properties()
at System.Management.ManagementBaseObject.GetPropertyValue(String propertyName)
at System.Management.ManagementBaseObject.get_Item(String propertyName)
at Base.CDriveSerialNumber.GetValue()
So I added the try-catch with AddSystemDriveSerialNumber instead and definitely see this issue less often, but I still see a bit of:
Microsoft.Management.Infrastructure.CimException: Access is denied.
?, in bool CimSyncEnumeratorBase<T>.MoveNext()
?, in string Wmi.GetSystemDriveSerialNumber()
?, in string SystemDriveSerialNumberDeviceIdComponent.GetValue()
Basically, what I'm asking is the following: what are the most stable id properties (least likely to change - like motherboard serial number as opposed to MAC address or OS Version) that also require the least permissions to access (for instance, I don't think I've ever seen an issue with my usage of AddProcessorId)?
Additionally, do you know of any resource that could rank all the component builders in DeviceId according to the permissions level required? I've been trying to find some resources online, but can't find anything