Beispiel #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text != String.Empty && comboBox2.GetItemText(comboBox2.SelectedItem) != String.Empty)
            {
                USBDeviceInfo selectedUsbDevice = (USBDeviceInfo)comboBox2.SelectedItem;

                var listConfig = File.ReadAllText(@"config.txt").Replace("\n", " ");

                if (listConfig.Contains(textBox2.Text + "-" + selectedUsbDevice.DeviceID))
                {
                    USBManager.Unlock(textBox2.Text);

                    MessageBox.Show(
                        "Папка успешно разблокирована",
                        "Разблокировка",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);

                    return;
                }

                MessageBox.Show(
                    "Неправильно выбрана папка либо USB-устройство",
                    "Разблокировка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
        }
Beispiel #2
0
        public static List <USBDeviceInfo> GetUSBDevices()
        {
            IEnumerable <string> usbDrivesLetters = from drive in new ManagementObjectSearcher("select * from Win32_DiskDrive WHERE InterfaceType='USB'").Get().Cast <ManagementObject>()
                                                    from o in drive.GetRelated("Win32_DiskPartition").Cast <ManagementObject>()
                                                    from i in o.GetRelated("Win32_LogicalDisk").Cast <ManagementObject>()
                                                    select string.Format("{0}\\", i["Name"]);

            var test = from drive in DriveInfo.GetDrives()
                       where drive.DriveType == DriveType.Removable && usbDrivesLetters.Contains(drive.RootDirectory.Name)
                       select drive;

            var devices = new List <USBDeviceInfo>();

            foreach (var item in test)
            {
                var device = new USBDeviceInfo(item.TotalSize + item.VolumeLabel + item.DriveFormat, item.Name);
                devices.Add(device);
            }

            return(devices);
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != String.Empty && comboBox1.GetItemText(comboBox1.SelectedItem) != String.Empty)
            {
                USBDeviceInfo selectedUsbDevice = (USBDeviceInfo)comboBox1.SelectedItem;

                USBManager.Lock(textBox1.Text);
                File.AppendAllText("config.txt", $"{textBox1.Text}-{selectedUsbDevice.DeviceID}-");

                MessageBox.Show(
                    "Папка успешно заблокирована",
                    "Блокировка",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);

                return;
            }

            MessageBox.Show(
                "Не выбрана папка либо не выбрано USB-устройство",
                "Блокировка",
                MessageBoxButtons.OK,
                MessageBoxIcon.Information);
        }