1

I am working on a .NET Core application. My requirement is that i have to get the UUID of motherboard. Code is:

static void Main(string[] args)
{
    string uuid = string.Empty;

    ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct");
    ManagementObjectCollection moc = mc.GetInstances();

    foreach (ManagementObject mo in moc)
    {
        uuid = mo.Properties["UUID"].Value.ToString();
        break;
    }

    Console.WriteLine("UUID : " + uuid);

    Console.ReadKey();
}

This code works perfectly fine on windows machine but when i move to the linux machine, i get the following error:

Unhandled exception. System.PlatformNotSupportedException: System.Management currently is only supported for Windows desktop applications.                                                                             
at System.Management.ManagementBaseObject..ctor(SerializationInfo info, StreamingContext context)
at System.Management.ManagementObject..ctor()
at System.Management.ManagementClass..ctor(String path)
at uniqueSystemId.Program.Main(String[] args)

Is System.Management not supported for linux ? If not, how can i get the UUID of motherboard on both linux and windows machine

Waleed Naveed
  • 1,590
  • 1
  • 16
  • 29
  • 3
    You are trying to use a Win32 specific API on Linux, it's not surprising it doesn't work. Does Linux even have a UUID? – Neil May 12 '20 at 12:35
  • agreed. How can i solve this problem ? @Neil – Waleed Naveed May 12 '20 at 12:36
  • 1
    You are probably going to have to delve into /proc or /dev, and it's unlikely there is some existing code to do it, so you are going to have to write it yourself. https://stackoverflow.com/questions/10152762/best-way-to-get-machine-id-on-linux – Neil May 12 '20 at 12:38
  • 1
    Yes. Bascically start programming and do not rely on WMI (which System.Management accesses) - Windows ( – TomTom May 12 '20 at 12:41
  • @TomTom thanks for the answer. Actually the command in the answer of the link you have mentioned requires authentication, my requirement is that i can not ask user to end the password, i have to find the UUID without any user interaction. So, basically i am asking, is there any way that i can do it with "System.Management" or any other better approach ? – Waleed Naveed May 12 '20 at 17:46
  • 1
    Nope. No way. System.Management ALSO requires authentication, except it will in a domain automatically use your account. – TomTom May 12 '20 at 18:14
  • thanks for information, much appreciated @TomTom – Waleed Naveed May 12 '20 at 18:18

0 Answers0