Need C # function to get sdcard server in .NET CF

I saw how it is written in C ++, which I do not know. I need a C # function that returns SDCard serial in .NET CF. Can someone help me write a function with it?

+4
source share
2 answers

First, I will say that if you buy SDF ($ 50), you get a source for this function, which you could then pull into your project and confuse.

If, however, you have more time than money, and you want to realize it yourself, I can point you in the right direction. I leave it for you to align all these parts together, but here are the steps:

First you must open the volume as follows:

IntPtr hFile = NativeMethods.CreateFile( string.Format("{0}\\Vol:", driveName), NativeMethods.GENERIC_READ, 0, 0, NativeMethods.OPEN_EXISTING, 0, 0); 

This gives you the ability to manage the drive. Then you just call IOCTL to get the repository id:

 byte[] data = new byte[512]; int returned; int result = NativeMethods.DeviceIoControl( hFile, IOCTL_DISK_GET_STORAGEID, IntPtr.Zero, 0, data, data.Length, out returned, IntPtr.Zero); if (result != 0) { m_storageID = STORAGE_IDENTIFICATION.FromBytes(data); } 

This gives you a binary representation of the STORAGE_IDENTIFICATION structure. Note that the structure is really just a description of the data header. It contains an offset to the actual serial number data, which is an ASCII string. The extraction looks something like this:

 int snoffset = BitConverter.ToInt32(data, 12); string sn = Encoding.ASCII.GetString(data, snoffset, data.Length - snoffset); return sn.TrimEnd(new char[] { '\0' }); 
+3
source

The smart device environment allows you to do this:

 foreach(var info in DriveInfo.GetDrives()) { string manufacturer = info.ManufacturerID ?? "[Not available]"); string serial = info.SerialNumber ?? "[Not available]"); } 

See here . Last year I asked the same question .

+1
source

Source: https://habr.com/ru/post/1315061/


All Articles