Search code examples
c#monohardwareuniqueidentifierserial-number

Determine hard drive serial number in mono?


I am developing a library in C# that generates a unique hardware ID using these 3 variables

  1. Machine name
  2. MAC address
  3. Hard drive serial number

I am able to get the machine name and MAC address in both .NET and Mono but I can only get the hard drive serial number in .NET. Does anyone know if there is any possible way to get the hard drive serial number in mono or should I just use another variable (ie: CPU name, Motherboard ID, etc)?


Solution

  • According to this documentation:

    Mac OS X doesn't support getting hard disk serial number from user-level application

    If the requirement to be root on mac is not a problem for you (or you skip the mac version), I have one brute way to solve the problem:

    Using this article or this question you can determine:

    1. Are you running Mono or .NET
    2. Which platform are you on

    If you know you are on the LINUX system, you can get hardrive serial through running such system command:

    /sbin/udevadm info --query=property --name=sda
    

    On mac you can use Disk Utility (as root) to get harddrive serial. On windows you can use the standard approach.