请问怎么获得无系统未格式化空白存储卡的容量等信息?
请问怎么获得无系统的存储卡的容量等信息?存储卡无系统引导无FAT表之类的,没有格式化,打个比方说所有扇区的所有字节值为零吧。计算机我的电脑里显示为可移动磁盘,但是是没有格式化的。
那么怎样用c#获得存储卡的容量大小,扇区大小,扇区总数等信息?
非得直接调用API么?当然能提供详细的调用API例子也行 --------------------编程问答-------------------- .net这些底层的东西无法获取到的。。。。 --------------------编程问答-------------------- .Net对此有封装。试一试。
using System.Management; //需添加引用
class Program
{
static readonly String[] arrManagementItem = new String[]{
"Availability",
"BytesPerSector",
"Capabilities",
"CapabilityDescriptions",
"Caption",
"CompressionMethod",
"ConfigManagerErrorCode",
"ConfigManagerUserConfig",
"CreationClassName",
"DefaultBlockSize",
"Description",
"DeviceID",
"ErrorCleared",
"ErrorDescription",
"ErrorMethodology",
//"FirmwareRevision",
"Index",
"InstallDate",
"Inte易做图ceType",
"LastErrorCode",
"Manufacturer",
"MaxBlockSize",
"MaxMediaSize",
"MediaLoaded",
"MediaType",
"MinBlockSize",
"Model",
"Name",
"NeedsCleaning",
"NumberOfMediaSupported",
"Partitions",
"PNPDeviceID",
"PowerManagementCapabilities",
"PowerManagementSupported",
"SCSIBus",
"SCSILogicalUnit",
"SCSIPort",
"SCSITargetId",
"SectorsPerTrack",
//"SerialNumber",
"Signature",
"Size",
"Status",
"StatusInfo",
"SystemCreationClassName",
"SystemName",
"TotalCylinders",
"TotalHeads",
"TotalSectors",
"TotalTracks",
"TracksPerCylinder",
};
static void Main(string[] args)
{
ManagementClass mc = new ManagementClass("Win32_DiskDrive");
foreach (ManagementObject mo in mc.GetInstances())
{
foreach (String mi in arrManagementItem)
{
Console.WriteLine("{0} : {1}", mi, mo[mi]);
}
}
Console.ReadKey();
}
}
参考:http://msdn.microsoft.com/en-us/library/windows/desktop/aa394132(v=vs.85).aspx --------------------编程问答-------------------- 楼上这个我已经试过的,不行,只能取得格式化过的信息,否则连容量都取不到好像 --------------------编程问答-------------------- 自己顶一顶 --------------------编程问答-------------------- 试下DeviceIoControl
--------------------编程问答-------------------- 这个貌似很难获取到吧。。。。如果能,一同等 --------------------编程问答--------------------
[DllImport("kernel32.dll")]
static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32.dll")]
static extern bool DeviceIoControl(IntPtr hDevice, int ioControlCode, IntPtr pInBuf, int inBufSize, out long diskSize, int outBufSize, out int pBytesReturned, IntPtr pOverlapped);
static void Main(string[] args)
{
long diskSize = 0;
int returnedBytes = 0;
// \\.\PhysicalDrive0 改成USB设备名
IntPtr handle = CreateFile(@"\\.\PhysicalDrive0", 0x80000000, 3, IntPtr.Zero, 3, 0, IntPtr.Zero);
DeviceIoControl(handle, 0x0007405c, IntPtr.Zero, 0, out diskSize, 8, out returnedBytes, IntPtr.Zero);
Console.WriteLine(diskSize);
}
用C#访问硬盘物理扇区和逻辑扇区的方法,API实现
C# 读写分区(按扇区) --------------------编程问答-------------------- --------------------编程问答--------------------
第一个我早就试过了,对于没有格式化的SD或者TF卡可以读写,但是对于格式化过后的,从零地址开始写,好像并没有写在物理的零地址开始处,不过我还没有反复试
谢谢楼上几位,我有时间再看看试试
希望更多答案
谢谢 --------------------编程问答--------------------
我可能是将物理磁盘号和逻辑磁盘号搞混了,可是怎样取得物理磁盘序号呢? --------------------编程问答--------------------
我可能是将物理磁盘号和逻辑磁盘号搞混了,可是怎样取得物理磁盘序号呢? --------------------编程问答--------------------
//using system.runtime.interopservices;
//using system.management;
//获取磁盘序列号
public string getharddiskid2()
{
try
{
System.Management.ManagementObjectSearcher cmicWmi = new ManagementObjectSearcher( "SELECT * FROM Win32_DiskDrive ");
System.UInt32 tmpUint32 = 0;
foreach(ManagementObject cmicWmiObj in cmicWmi.Get())
{
tmpUint32 = Convert.ToUInt32(cmicWmiObj[ "signature "].ToString());
}
this.textBox1.Text = tmpUint32.ToString();
this.gProgressBar1.Value ++;
}
catch(Exception ex1)
{
throw new Exception(ex1.ToString());
}
}
参考http://archive.cnblogs.com/a/1369514/ --------------------编程问答-------------------- 楼上,谢谢回答
还没来得及仔细看全部
不过我说的是不是怎样取得所有的物理磁盘号,而是怎样根据用户看到选择的逻辑盘符获得物理盘号
罗列物理盘号我早就取得过,关键是怎么知道哪个物理盘号是对应需要操作的移动存储设备? --------------------编程问答-------------------- 这个真心不会了。给楼主顶一下,顺便等答案。很高端的样子。 --------------------编程问答--------------------
这个真心不会了,靠你自己探索了,探索出来分享一下,谢谢 --------------------编程问答-------------------- 关注一下,顺便等等问题答案
补充:.NET技术 , C#