Compact Framework - Get Storage Card Serial Number

半腔热情 提交于 2019-11-30 21:51:04

The Smart Device Framework provides a mechanism to get SD Card serial numbers and manufacturer IDs.

I'm not on a machine that I can get the syntax for you but I believe you can use the System.IO namespace to get IO based attributes.

First get a DirectoryInfo to the storage card. (I'm not 100% on the code here, you may need to test, I'll update it if I can get to my machine)

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 on the DirectoryInfo that code returns. Thanks to the joys of debugging you should be able to see if the serial number is one of the available properties.

If not, you may need to look to something a bit more unmanaged.

Hope this helps.

You need to use some unmanaged APIs. Specifically, DeviceIoControl using a 'control code' of IOCT_DISK_GET_STORAGEID. This will, in turn, return a STORAGE_IDENTIFICATION structure.

Here's where it gets a bit tricky, as STORAGE_IDENTIFICATION uses a property (dwSerialNumOffset) to specify the (memory) offset from the beginning of the structure, which would be difficult to translate into interop calls.

Edit: Found a VB.NET implementation on the MSDN forums

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!