I want to create a windows application in c#.net to disable usb port by below code
Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR","Start",4,Microsoft.Win32.RegistryValueKind.DWord);MessageBox.Show("Disabled");after that I want to create a listbox with items of usb devices connected to windows.also for this I use belowe code
C#
List<USBDeviceInfo> GetUSBDevices()
{
List<USBDeviceInfo> devices = new List<USBDeviceInfo>();
ManagementObjectCollection collection;
using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
collection = searcher.Get();
foreach (var device in collection)
{ devices.Add(new USBDeviceInfo(
(string)device.GetPropertyValue("DeviceID"),
(string)device.GetPropertyValue("PNPDeviceID"),
Code
(string)device.GetPropertyValue("Description")
));
}
collection.Dispose();
return devices;
}C#
var usbDevices = GetUSBDevices();
foreach (var usbDevice in usbDevices)
{
listBox1.Items.Add(string.Format("Device ID: {0} Description: {1}",usbDevice.DeviceID, usbDevice.Description));//, usbDevice.PnpDeviceID, usbDevice.Description));
}I want to do this for security not to allow any usb device to connect to copy any information from windows.
So how can I enable usb device by it's Id in c#.net
Answers
Know the answer? Post it. Somebody with the same question will find it here.