Добавить Program.cs

Обязательна установка NuGet пакета System.Management.
This commit is contained in:
2026-06-10 23:53:05 +03:00
parent 48f5f7ecc2
commit 30a4f05ee1
+55
View File
@@ -0,0 +1,55 @@
using System.Management;
class Drivers
{
public string? Path_Device_driver { get; set; }
public string? Name_Device_driver { get; set; }
public string? Status_Device_driver { get; set; }
}
class View_driver
{
static void Main(string[] args)
{
List<Drivers> drivers = new List<Drivers>();
string unknownName = "Неизвестное устройство";
var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity");
foreach (ManagementObject obj in searcher.Get())
{
var driver = new Drivers
{
Name_Device_driver = obj["Name"]?.ToString() ?? unknownName,
Status_Device_driver = obj["Status"]?.ToString() ?? unknownName,
Path_Device_driver = obj["ClassGuid"]?.ToString() ?? unknownName
};
drivers.Add(driver);
var statusColor = driver.Status_Device_driver switch
{
"OK" => ConsoleColor.Green,
"Error" => ConsoleColor.Red,
"Degraded" => ConsoleColor.Yellow,
_ => ConsoleColor.Gray
};
var nameColor = driver.Name_Device_driver == unknownName
? ConsoleColor.Red
: ConsoleColor.DarkGray;
Console.Write("Имя: ");
Console.ForegroundColor = nameColor;
Console.Write(driver.Name_Device_driver);
Console.ResetColor();
Console.Write(" | Статус: ");
Console.ForegroundColor = statusColor;
Console.Write(driver.Status_Device_driver);
Console.ResetColor();
Console.Write(" | Путь: ");
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.Write($"{driver.Path_Device_driver}\n");
Console.ResetColor();
Thread.Sleep(5);
}
}
}