/// <summary> /// Must bve used to uninstall device when this app is 32-bit, but runs on 64-bit windows. /// This is because SetupDiCallClassInstaller throws ERROR_IN_WOW64 (ex.ErrorCode = 0xE0000235) /// when application architecture do not match OS architecture. /// </summary> /// <remarks>Must be executed in administrative mode.</remarks> public static void UnInstallDevice(string deviceId, ProcessWindowStyle style = ProcessWindowStyle.Hidden) { //// If architecture match then... //if (Environment.Is64BitProcess == Environment.Is64BitOperatingSystem) //{ // // Works only on matching architecture. // foreach (var hwid in deviceIds) // { // DeviceDetector.RemoveDevice(hwid); // } //} //else //{ // Use alternative method. // Extract files first. ExtractHidGuardianFiles(true); var folder = GetHidGuardianPath(); var fullPath = System.IO.Path.Combine(folder, "devcon.exe"); JocysCom.ClassLibrary.Win32.UacHelper.RunElevated( fullPath, "remove \"" + deviceId + "\"", style, true); //} // Make sure that device is reinserted. DeviceDetector.ScanForHardwareChanges(); }
/// <summary> /// Must remove and re-add devices for HidGuardian filters to take effect. /// </summary> static void ResetDevices(params string[] deviceIds) { foreach (var hwid in deviceIds) { DeviceDetector.RemoveDevice(hwid); } DeviceDetector.ScanForHardwareChanges(); }
/// <summary> /// Must bve used to uninstall device when this app is 32-bit, but runs on 64-bit windows. /// This is because SetupDiCallClassInstaller throws ERROR_IN_WOW64 (ex.ErrorCode = 0xE0000235) /// when application architecture do not match OS architecture. /// </summary> /// <param name="deviceId"> /// Device Hardware ID ("HID\VID_046D&PID_C219") or /// Device Instance ID prefixed with '@' (@"HID\VID_046D&PID_C219\7&29C26453&0&0000"). /// </param> /// <remarks>Must be executed in administrative mode.</remarks> public static void UnInstallDevice(string deviceId, ProcessWindowStyle style = ProcessWindowStyle.Hidden) { // Extract files first. ExtractHidGuardianFiles(true); var folder = GetHidGuardianPath(); var exePath = Path.Combine(folder, GetDevConPath()); UacHelper.RunElevated( exePath, "remove \"" + deviceId + "\"", style, true); // Make sure that device is re-inserted. DeviceDetector.ScanForHardwareChanges(); }