예제 #1
0
 public static void EnumDevicesCallback(
     Native.DeviceInfoListHandle devs, ref Native.SP_DEVINFO_DATA devInfo,
     string deviceId, Parameters parms
     )
 {
     // For each device, enumerate its device interfaces that are of type Volume
     Native.EnumerateDeviceInterfaces(
         devs, ref devInfo, ref DEVINTERFACE_VOLUME, EnumInterfacesCallback, parms
         );
 }
예제 #2
0
        public static void DoEnableDisable(
            Native.DeviceInfoListHandle devs, ref Native.SP_DEVINFO_DATA devInfo,
            string deviceId, EnableDisableParameters parms
            )
        {
            if (devInfo.ClassGuid != parms.ClassGuid)
            {
                return;
            }
            if (devInfo.DevInst != parms.DevInst)
            {
                return;
            }

            var options = parms.AppParams.Options;

            if ((options.Count == 0) || options.Contains("disable"))
            {
                Console.WriteLine(
                    "// Physical ID for volume {0} is #{1}. You can use this ID to re-enable the volume.",
                    parms.DriveLetter, devInfo.DevInst
                    );

                Console.Write("Disabling volume {0}... ", parms.DriveLetter);
                try {
                    Native.ChangeDeviceEnabledState(
                        devs, ref devInfo,
                        DiClassInstallState.DICS_DISABLE,
                        DiClassInstallScope.DICS_FLAG_CONFIGSPECIFIC,
                        DiClassInstallFunction.DIF_PROPERTYCHANGE
                        );

                    Console.WriteLine("ok.");
                } catch (Exception ex) {
                    Console.WriteLine("failed.");
                }
            }

            if ((options.Count == 0) || options.Contains("enable"))
            {
                Console.Write("Enabling volume {0}... ", parms.DriveLetter);
                try {
                    Native.ChangeDeviceEnabledState(
                        devs, ref devInfo,
                        DiClassInstallState.DICS_ENABLE,
                        DiClassInstallScope.DICS_FLAG_CONFIGSPECIFIC,
                        DiClassInstallFunction.DIF_PROPERTYCHANGE
                        );

                    Console.WriteLine("ok.");
                } catch (Exception ex) {
                    Console.WriteLine("failed.");
                }
            }
        }
예제 #3
0
        public static void EnumInterfacesCallback(
            Native.DeviceInfoListHandle devs, ref Native.SP_DEVINFO_DATA devInfo,
            ref Native.SP_DEVICE_INTERFACE_DATA interfaceData,
            string devicePath, Parameters appParams
            )
        {
            // We've got a device interface of type Volume. See if it matches either of our selection criteria

            var parms = new EnableDisableParameters {
                ClassGuid = devInfo.ClassGuid,
                DevInst   = devInfo.DevInst,
                AppParams = appParams
            };

            if (appParams.InstanceIDs.Contains(devInfo.DevInst))
            {
                parms.DriveLetter = String.Format("#{0}", devInfo.DevInst);
            }
            else
            {
                DeviceNumber devNumber;
                Exception    failureReason;

                if (!GetDeviceNumber(devicePath, out devNumber, out failureReason))
                {
                    return;
                }

                string driveLetter;
                if (!appParams.DriveLetters.TryGetValue(devNumber, out driveLetter))
                {
                    return;
                }

                appParams.DriveLetters.Remove(devNumber);

                parms.DriveLetter = driveLetter;
            }

            Native.EnumerateDevices(
                null, DiGetClassFlags.DIGCF_ALLCLASSES,
                null, DoEnableDisable, parms
                );
        }