visual studio 2005 - Read USB Device Serial number in C# -


Is there any way to use USB device serial numbers and data in USD in Text Studio 2005?

Try this:

  USBSerialNumber usb = new USBSerialNumber (); String serial = usb.getSerialNumberFromDriveLetter ("f: \"); MessageBox.Show (serial);  

The USBSerialNumber class is internal to:

  using the system; Using System.Collections.Generic; Using System.Text; Using System.Management; Namespace USBDrive SerialNumber {PUBLIC SQUARE USSS ArielNumber {string_surialnumber; String _driveLetter; Public string getSerialNumberFromDriveLetter (string drive liter) {this._driveLetter = driveLetter.ToUpper (); If (! This._driveLetter.Contains (":")) {this._driveLetter + = ":"; } MatchDriveLetterWithSerial (); Turn it back. } Private Zero MatchDriver Letter with Serial () {string [] diskArray; String drive number; String drive liter; ManagementObjectSearcher searcher1 = New Management Object Search ("Select * from Win32_LogicalDiskToPartition"); The forerunner (finder in the finder DM Gate ()) {discare = null; DriveLetter = getValueInQuotes (DM ["Dependent"]. ToString ()); DiscAre = getValueInQuotes (DM ["predecessor"]. ToString ()). Split (','); DriveNumber = DiskArray [0]. Remove (0, 6). Trim (); If (drive litter == this._driveLetter) {/ * this is where we get the drive serial * / Management object search disk = new management object search ("SELECT * FROM Win32_DiskDrive"); ("Disk" ["name"] ToString () == ("\\\\. \ PHYSICALDRIVE" + drive number) and disk ["interface type"]. () == "USB") {this._serialNumber = ParseSerialFromDeviceID (Disk ["PNPDeviceID"]. ToString ()); }}}}} Private string parseSerialFromDeviceID (string deviceId) {string [] splitDeviceId = deviceId.Split ('\\'); String [] serial array; String serial; Int arrayLen = splitDeviceId.Length-1; SerialArray = splitDeviceId [arrayLen]. Split ('& amp;'); Serial = serial array [0]; Return serial; } Private string getValueInQuotes (string in well) {string parcedValue = ""; Int posFoundStart = 0; Int posFoundEnd = 0; PosFoundStart = inValue.IndexOf ("\" "); posFoundEnd = inValue.IndexOf (" \ "", posFoundStart + 1); ParsedValue = inValue.Substring (posFoundStart + 1, (posFoundEnd - posFoundStart) - 1); Return parsing value; }}}  

Source:


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -