Compact Framework - Get Storage Card Serial Number

我只是一个虾纸丫 提交于 2019-11-30 17:31:25

问题


Morning all,

How would I go about getting the serial number of the storage/sd card on my mobile device? I am using C#.Net 2.0 on the Compact Framework V2.0.

Thanks.


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/552681/compact-framework-get-storage-card-serial-number

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