Esempio n. 1
0
        private static bool GetKeyUSB()
        {
            List <USBData> usb = GetAllUSB();

            foreach (USBData arg in usb)
            {
                string path = arg.logicalDisk + @"\ИСКРА.LIC";
                if (Directory.Exists(path))
                {
                    KeyUSB          = arg;
                    KeyUSB.pathDir  = path;
                    KeyUSB.pathFile = path + @"\ИСКРА.LIC";
                    break;
                }
            }
            if (KeyUSB == null)
            {
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        private static List <USBData> GetAllUSB()
        {
            List <USBData>  usb       = new List <USBData>();
            List <string[]> diskDrive = SelectWMI("Win32_DiskDrive", new string[] { "DeviceID", "InterfaceType", "SerialNumber" });
            List <string>   partition = new List <string>();
            List <string>   logical   = new List <string>();
            List <string[]> volume;

            foreach (string[] arg in diskDrive)
            {
                if (arg[1] == "USB")
                {
                    USBData usbData = new USBData();

                    /*if (arg[2] == null)
                     * usbData.serialNumber = "";
                     * else*/
                    usbData.serialNumber = arg[2];
                    if (usbData.serialNumber == null)
                    {
                        usbData.serialNumber = "";
                    }
                    usb.Add(usbData);
                    List <string> part = AssociatorsWMI("Win32_DiskDrive.DeviceID='" + arg[0] + "'", "Win32_DiskDriveToDiskPartition", "DeviceID");
                    foreach (string data in part)
                    {
                        partition.Add(data);
                    }
                }
            }
            if (usb.Count == 0)
            {
                return(usb);
            }
            foreach (string arg in partition)
            {
                List <string> tempLogical = AssociatorsWMI("Win32_DiskPartition.DeviceID='" + arg + "'", "Win32_LogicalDiskToPartition", "Name");
                foreach (string data in tempLogical)
                {
                    logical.Add(data);
                }
            }
            for (int i = 0; i < logical.Count; i++)
            {
                usb[i].logicalDisk = logical[i];
            }
            volume = SelectWMI("Win32_LogicalDisk", new string[] { "Name", "VolumeSerialNumber" });
            int indexDisk = 0;

            foreach (string[] arg in volume)
            {
                if (usb.Count == indexDisk)
                {
                    break;
                }
                if (arg[0] == usb[indexDisk].logicalDisk)
                {
                    usb[indexDisk++].serialVolume = arg[1];
                }
            }
            return(usb);
        }