WMI 已弃用:现在如何从 .Net Core 查询?
WMI deprecated: how to query from .Net Core now?
我读过 here that Microsoft is deprecating WMI。我需要在 .NET Core 中启动一个项目并从 Windows 查询信息,例如Win32_OperatingSystem
或 Win32_LogicalDisk
。
我读到您应该避免在 PowerShell 中使用 Get-WmiObject
,而是使用 Get-CimInstance
。现在在 .Net Core 中应该使用什么(Nuget/library)来查询这些信息?
您可以使用 Windows 兼容包 (article, nuget) for .NET Core which gives you access to a lot of Windows-only APIs but restricts your app to running only on Windows, probably not something you're worried about. This compatibility pack is also known as platform extensions. With this you would need to learn how to use the classes in the System.Management
namespace (API Ref, example code 1, example code 2)。继续探索 API 示例。
另外,微软貌似有更新的类似CIM的跨平台开源系统。虽然显然不是 WMI 中所有可用的东西都适用于此,所以你的里程会有所不同:https://www.nuget.org/packages/Microsoft.Management/ and https://www.nuget.org/packages/Microsoft.Management.Infrastructure/
希望对您有所帮助。
我读过 here that Microsoft is deprecating WMI。我需要在 .NET Core 中启动一个项目并从 Windows 查询信息,例如Win32_OperatingSystem
或 Win32_LogicalDisk
。
我读到您应该避免在 PowerShell 中使用 Get-WmiObject
,而是使用 Get-CimInstance
。现在在 .Net Core 中应该使用什么(Nuget/library)来查询这些信息?
您可以使用 Windows 兼容包 (article, nuget) for .NET Core which gives you access to a lot of Windows-only APIs but restricts your app to running only on Windows, probably not something you're worried about. This compatibility pack is also known as platform extensions. With this you would need to learn how to use the classes in the System.Management
namespace (API Ref, example code 1, example code 2)。继续探索 API 示例。
另外,微软貌似有更新的类似CIM的跨平台开源系统。虽然显然不是 WMI 中所有可用的东西都适用于此,所以你的里程会有所不同:https://www.nuget.org/packages/Microsoft.Management/ and https://www.nuget.org/packages/Microsoft.Management.Infrastructure/
希望对您有所帮助。