public static bool Restart(USBDevice Device) { bool result; Native.SP_PROPCHANGE_PARAMS prms = new Native.SP_PROPCHANGE_PARAMS(); unsafe { int size = Marshal.SizeOf(typeof(Native.SP_PROPCHANGE_PARAMS)); prms.ClassInstallHeader.cbSize = (uint)Marshal.SizeOf(typeof(Native.SP_CLASSINSTALL_HEADER)); prms.ClassInstallHeader.InstallFunction = Native.DIF_PROPERTYCHANGE; prms.StateChange = Native.DICS_PROPCHANGE; prms.Scope = Native.DICS_FLAG_CONFIGSPECIFIC; prms.HwProfile = 0; result = Native.SetupDiSetClassInstallParams(Device.DevInfoSet, ref Device.DevInfoData, (IntPtr)(&prms), Marshal.SizeOf(typeof(Native.SP_PROPCHANGE_PARAMS))); if (!result) { return(false); } return(Native.SetupDiCallClassInstaller(Native.DIF_PROPERTYCHANGE, Device.DevInfoSet, ref Device.DevInfoData)); } }
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); }
static bool OpenFilterParamsKey(USBDevice Device, out UIntPtr hKey) { UIntPtr PrevKey = Native.SetupDiCreateDevRegKey(Device.DevInfoSet, ref Device.DevInfoData, Native.DICS_FLAG_GLOBAL, 0, Native.DIREG_DEV, IntPtr.Zero, IntPtr.Zero); hKey = UIntPtr.Zero; if (PrevKey == null) { return(false); } if (Native.RegOpenKeyEx(PrevKey, "KvntUsbDrvrParams", Native.RegOption.NonVolatile, Native.RegSAM.AllAccess, out hKey) != Native.ERROR_SUCCESS) { Native.RegCloseKey(PrevKey); return(false); } Native.RegCloseKey(PrevKey); 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 Eject(USBDevice Device) { return(Native.CM_Request_Device_Eject_NoUi((int)Device.DevInfoData.DevInst, IntPtr.Zero, null, 0, 0) == 0 ? true : false); }
public static bool IsFilterKeyInstalled(USBDevice Device, string DriverName) { return(IsKeyInstalled(DriverName) && IsFilterInstalled(Device, DriverName)); }
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); }