Compact Framework - get the serial number of the memory card

Morning everything

How do I get the serial number of the memory card / sd on a mobile device? I am using C # .Net 2.0 on Compact Framework V2.0.

Thanks.

+3
source share
3 answers

The Smart Device Framework provides a mechanism for retrieving the serial numbers of SD cards and manufacturer identifiers.

+2
source

I am not on the machine to get the syntax for you, but I believe that you can use the System.IO namespace to get IO-based attributes.

First, enter DirectoryInfo on the memory card. (I'm not 100% here, you may have to test, I will update it if I can get to my car)

public DirectoryInfo GetStorageCard() { DirectoryInfo deviceRoot = new DirectoryInfo("/"); foreach (DirectoryInfo dir in deviceRoot.GetDirectories()) if (dir.Attributes == FileAttributes.Directory & dir.Attributes = FileAttributes.Temporary) return dir; } 

Then check all the properties in DirectoryInfo that the code returns. Thanks to the joys of debugging, you need to make sure that the serial number is one of the available properties.

If not, you may need to reinstall a bit.

Hope this helps.

+1
source

You need to use some unmanaged APIs. In particular, DeviceIoControl using the "control code" IOCT_DISK_GET_STORAGEID . This, in turn, will return the STORAGE_IDENTIFICATION structure.

Here, where it gets a little complicated, because STORAGE_IDENTIFICATION uses the (dwSerialNumOffset) property to indicate the offset (memory) from the beginning of the structure, which would be difficult to translate to interop calls.

Edit: Found VB.NET Implementation on MSDN Forums

+1
source

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


All Articles