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(); 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); }
private static void ReadKey() { KeyReadUSB = new USBData(); FileInfo fileInfo = new FileInfo(KeyUSB.pathFile); KeyUSB.dateTimeCreate = fileInfo.CreationTime.ToString("dd/MM/yy HH:mm"); string inputText = File.ReadAllText(KeyUSB.pathFile); string[] input = inputText.Split(new string[] { "#?!\r\n" }, StringSplitOptions.None); KeyReadUSB.numberKey = Decoding(input[0], KeyUSB.serialVolume); KeyReadUSB.versionKey = Decoding(input[1], KeyUSB.serialVolume); KeyReadUSB.owner = Decoding(input[2], KeyUSB.serialVolume); KeyReadUSB.serialNumber = Decoding(input[3], KeyUSB.serialVolume); KeyReadUSB.countActivate = Convert.ToInt32(Decoding(input[4], KeyUSB.serialVolume)); KeyReadUSB.dateTimeCreate = Decoding(input[5], KeyUSB.serialVolume); }
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); }