private void button2_Click(object sender, RoutedEventArgs e) { if (lbUSBDevices.SelectedIndex >= 0 && lbUSBDevices.SelectedIndex < USBDevices.Count) { if (USBDriver.AnyFilterInstalled(USBDevices, DriverName)) { USBDriver.UninstallFilter(USBDevices[lbUSBDevices.SelectedIndex], DriverName, Native.SPDRP_LOWERFILTERS); USBDriver.UnistallKey(DriverName); USBUtils.Restart(USBDevices[lbUSBDevices.SelectedIndex]); button2.Content = "Install"; } else { if (System.IO.File.Exists(tbLogDir.Text + lbUSBDevices.Items[lbUSBDevices.SelectedIndex].ToString() + @".log")) { System.IO.File.Delete(tbLogDir.Text + lbUSBDevices.Items[lbUSBDevices.SelectedIndex].ToString() + @".log"); } USBDriver.InstallKey(@"..\..\..\Driver\objchk_wxp_x86\i386\" + DriverName + ".sys"); USBDriver.InstallFilter(USBDevices[lbUSBDevices.SelectedIndex], DriverName, Native.SPDRP_LOWERFILTERS, 10000000, tbLogDir.Text + lbUSBDevices.Items[lbUSBDevices.SelectedIndex].ToString() + @".log"); USBUtils.Restart(USBDevices[lbUSBDevices.SelectedIndex]); button2.Content = "Remove"; } } }
private void button3_Click(object sender, RoutedEventArgs e) { if (lbUSBDevices.SelectedIndex >= 0 && lbUSBDevices.SelectedIndex < USBDevices.Count) { USBUtils.Restart(USBDevices[lbUSBDevices.SelectedIndex]); } }
public void UpdateDevicesList() { lbUSBDevices.Items.Clear(); USBDevices = USBUtils.GetUSBDevices(); int i = 0; foreach (USBDevice Device in USBDevices) { lbUSBDevices.Items.Add(Device.Caption + " " + i.ToString()); i++; } }
public static bool UninstallFilter(USBDevice Device, string DriverName, uint FilterType) { byte[] Property = null; uint PropertySize = 0; bool success; Property = USBUtils.GetDeviceRegistryProperty(Device.DevInfoSet, Device.DevInfoData, FilterType, ref PropertySize); if (Property == null || (Property[0] == 0)) { return(false); } else { if (!StrCmp(Property, PropertySize, DriverName)) { return(false); } else { /*Property = BytesFromString(DriverName); * PropertySize = (uint)Property.Length;*/ for (int i = 0; i < Property.Length; i++) { Property[i] = 0; } success = Native.SetupDiSetDeviceRegistryProperty(Device.DevInfoSet, ref Device.DevInfoData, FilterType, Property, PropertySize + 1); if (!success) { return(false); } } } UIntPtr hKey; OpenFilterParamsKey(Device, out hKey); if (!RegDeleteFilterParams(hKey)) { return(false); } return(true); }
public static bool IsFilterInstalled(USBDevice Device, string DriverName) { byte[] Property = null; uint PropertySize = 0; Property = USBUtils.GetDeviceRegistryProperty(Device.DevInfoSet, Device.DevInfoData, Native.SPDRP_LOWERFILTERS, ref PropertySize); if (Property != null && StrCmp(Property, PropertySize, DriverName)) { return(true); } else { return(false); } }
public static bool AnyFilterInstalled(List <USBDevice> Devices, string DriverName) { byte[] Property = null; bool FilterExists = false; uint PropertySize = 0; for (int i = 0; i < Devices.Count; i++) { Property = USBUtils.GetDeviceRegistryProperty(Devices[i].DevInfoSet, Devices[i].DevInfoData, Native.SPDRP_LOWERFILTERS, ref PropertySize); if (Property != null && StrCmp(Property, PropertySize, DriverName)) { FilterExists = true; break; } } return(FilterExists); }
public static bool InstallFilter(USBDevice Device, string DriverName, uint FilterType, uint Flags, string LogPath) { byte[] Property = null; uint PropertySize = 0; bool success; Property = USBUtils.GetDeviceRegistryProperty(Device.DevInfoSet, Device.DevInfoData, FilterType, ref PropertySize); if (Property == null || (Property[0] == 0)) { Property = BytesFromString(DriverName); PropertySize = (uint)Property.Length; int counter = 0; success = false; do { success = Native.SetupDiSetDeviceRegistryProperty(Device.DevInfoSet, ref Device.DevInfoData, FilterType, Property, PropertySize); counter++; }while ((!success) && (counter < 100)); if (!success) { return(false); } } else { if (StrCmp(Property, PropertySize, DriverName)) { //return false; // драйвер установлен } Property = BytesFromString(DriverName); PropertySize = (uint)Property.Length; success = Native.SetupDiSetDeviceRegistryProperty(Device.DevInfoSet, ref Device.DevInfoData, FilterType, Property, PropertySize); if (!success) { return(false); } } UIntPtr hKey; CreateFilterParamsKey(Device, out hKey); if (!RegWriteFilterParams(hKey, Flags, LogPath)) { Native.RegCloseKey(hKey); return(false); } Native.RegCloseKey(hKey); return(true); }