System.Management equivelants?
See original GitHub issuePreviously, I’ve been using this to generate a unique ID (based on this SO answer):
public static string GetUniquePCIdentifier()
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
string drive = "C";
ManagementObject dsk = new ManagementObject(
@"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();
return cpuInfo + volumeSerial;
}
Running that on my computer gives me the ID BFEBFBFF000306C34408F4F4
.
I figured the equivalent in the DeviceId library would be something like:
public static string GetUniquePCIdentifier()
{
return new DeviceIdBuilder().AddProcessorId().AddSystemDriveSerialNumber().ToString();
}
But that gives me the ID nS9mx7meCmiAvsfZpyTLK_aQtGkgPljmld7nl4po35A
(which isn’t anywhere close to what I had above). Does the DeviceId library use one of the hashing formatters by default?
If possible, I’d like to migrate to this library and still keep generating the same IDs as I was before. Am I using the library correctly or is this just not possible?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Top 10 AWS Systems Manager Alternatives & Competitors
Alternatives to AWS Systems Manager · Hashicorp Terraform · ManageEngine Endpoint Central · Freshservice · Microsoft System Center · EV Reach · Kaseya...
Read more >Top 10 Systeme.io Alternatives & Competitors
Find top-ranking Systeme.io alternatives and competitors. Read the latest reviews and find the best Email Marketing Software software for your business.
Read more >9 Best SCCM Alternatives for 2023 (Paid & Free)
SCCM is one of the most popular systems management tools. Ηowever, there is a range of alternatives that we look into in this...
Read more >11 Best Systems Manager Certifications in 2023
The most common combination of systems manager certifications include: Project Management Professional (PMP), IT Information Library Foundations ...
Read more >Best IT Systems Management Tools
All big computer networks need multidimensional and reliable management tools for optimizing work of each node and application in system.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Perfect - I implemented your examples and that provided me exactly what I needed!
I plan on using this cross-platform so implementing the DeviceId library seems like a good way to go. I’m aware that processorId isn’t available for OSX according to the readme, so I’ll generate a different combination for OSX.
Thanks for all your help!
I was just typing up a reply but I see you’ve solved half of your issue already. Yep, you’re on the right track. There’s
WmiDeviceIdComponent
which will let you get the system drive serial number, but it’ll give you results for each drive, not just C:\ as per your example. You can implement a customIDeviceIdComponent
that will do what you want, though. Your next issue will be that theStringDeviceIdFormatter
concats the component values with a.
rather than a space, but a customIDeviceIdFormatter
can be used to get the result you want. Give me a few minutes and I’ll post an example.