Hi, @Vishal2 Bansal. Welcome to Microsoft Q&A.
You could get all the devices of your current computer through the following code.
string query = "SELECT * FROM Win32_PnPEntity";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
foreach (ManagementObject device in searcher.Get())
{
Console.WriteLine($"Name: {device["Name"]}" + "\n");
}
These devices correspond to the devices in Device Manager
(Control Panel
->View by
Select Large icons
or Small icons
->Device Manager
).The order may not be consistent.
Of course, you could also replace Win32_PnPEntity with Win32_VideoController or Win32_USBController for more precise designation.
Find the device you want to shut down and start shutting down the device by calling ManagementObject.InvokeMethod.
Start the device
device.InvokeMethod("Enable", null);
Turn off the device
device.InvokeMethod("Disable", null);
After execution, you could observe that the status of the device has changed.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.