A class used to list / activate / deactivate and reset USB devices connected to the computer More...
Public Types | |
enum | DeviceAction { Disable, Reset, Enable } |
Public Member Functions | |
setupapi (IntPtr formHandle) | |
void | HookFormToHardwareChange (IntPtr formHandle) |
Used to hook a window on hardware events More... | |
void | DisconnectFromHardwareNotifications () |
bool | ActivateDevice (string deviceName) |
Activate a device by its name More... | |
bool | DeactivateDevice (string deviceName) |
Deactivate a device by its name More... | |
bool | ResetDevice (string deviceName) |
Reset a device by its name More... | |
string [] | GetDevicesList () |
Returns a sorted list of all computer's devices More... | |
A class used to list / activate / deactivate and reset USB devices connected to the computer
Example of use : setupapi usb = new setupapi(this.Handle);
To act on device's state: usb.ActivateDevice("name_of_the_device"); usb.DeactivateDevice("name_of_the_device"); usb.ResetDevice("name_of_the_device");
To list attached devices: foreach (string device in usb.GetDevicesList()) listBox1.Items.Add(device);
If you wish to be notified of devices status change, add this method to your app: protected override void WndProc(ref Message m) { if (m.WParam.ToInt32() == SpringCard.LibCs.Native.DBT_DEVNODES_CHANGED) { listBox1.Items.Clear(); string[] HardwareList = usb.GetDevicesList(); foreach (string s in HardwareList) { //if(s.ToLower().StartsWith("s")) listBox1.Items.Add(s); } label1.Text = listBox1.Items.Count.ToString() + " Devices Attached"; } break; } } base.WndProc(ref m); }
bool SpringCard.LibCs.setupapi.ActivateDevice | ( | string | deviceName | ) |
Activate a device by its name
deviceName |
bool SpringCard.LibCs.setupapi.DeactivateDevice | ( | string | deviceName | ) |
Deactivate a device by its name
deviceName |
string [] SpringCard.LibCs.setupapi.GetDevicesList | ( | ) |
Returns a sorted list of all computer's devices
void SpringCard.LibCs.setupapi.HookFormToHardwareChange | ( | IntPtr | formHandle | ) |
Used to hook a window on hardware events
form |
bool SpringCard.LibCs.setupapi.ResetDevice | ( | string | deviceName | ) |
Reset a device by its name
deviceName |