question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.Management equivelants?

See original GitHub issue

Previously, 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:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
derekantricancommented, Nov 4, 2020

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!

1reaction
MatthewKingcommented, Nov 4, 2020

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 custom IDeviceIdComponent that will do what you want, though. Your next issue will be that the StringDeviceIdFormatter concats the component values with a . rather than a space, but a custom IDeviceIdFormatter can be used to get the result you want. Give me a few minutes and I’ll post an example.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found