Not able to use System.Management.dll in Dot Net Core

后端 未结 4 1339
孤街浪徒
孤街浪徒 2021-02-18 13:31

How should I gather Hardware Info if System.Management.dll is not compatible with Dot Net Core.

How do I get the Machine info like Processo

4条回答
  •  感情败类
    2021-02-18 14:19

    I am currently porting a Net Framework project that uses System.Management to get some hardware info, and I also got to a dead end because System.Management is not compatible with Net Core.

    The workaround I found was to use Process.Start from System.Diagnostics to execute powershell commands to get that information, for instance, to get the motherboard serial number you can use the command Get-WmiObject Win32_BaseBoard | select SerialNumber, you can then change the command to process the output and only have the serial number, or even process the output programatically.

    You can also add some ifs, that depending on the current OS you can provide to the Process.Start specific OS commands, for instance, for linux you would need to process a dmidecode related command.

    The only negative side in this approach is that its A LOT SLOWER whem compared with System.Management.

提交回复
热议问题