you should call WinApi DeviceIoContorl,there is some examples
// ====================================== MS KB Q115828 =======================
using System.Runtime.InteropServices;internal struct DISK_GEOMETRY
{
public long Cylinders;
public int MediaType;
public int TracksPerCylinder;
public int SectorsPerTrack;
public int BytesPerSector;
}class TestIoCtl
{
[DllImport("kernel32.dll")]
public static extern IntPtr CreateFile(
string lpFileName, int dwDesiredAccess, int dwShareMode,
IntPtr lpSecurityAttributes, int dwCreationDisposition,
int dwFlagsAndAttributes, IntPtr hTemplateFile ); private const int FILE_SHARE_READ = 1;
private const int OPEN_ALWAYS = 4;
private const int INVALID_HANDLE_VALUE = -1;
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern bool DeviceIoControl(
IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
IntPtr lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, IntPtr lpOverlapped ); private const int IOCTL_DISK_GET_MEDIA_TYPES = 0x00070c00; static void Main(string[] args)
{
IntPtr hflp = CreateFile( @"\\.\A:", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_ALWAYS, 0, IntPtr.Zero );
if( (int)hflp == INVALID_HANDLE_VALUE )
{ Console.WriteLine("CreateFile failed"); return; } Type ts = typeof( DISK_GEOMETRY );
int ss = Marshal.SizeOf( ts );
int ssa = ss * 20;
IntPtr mptr = Marshal.AllocHGlobal( ssa );
int byret = 0;
bool ok = DeviceIoControl( hflp, IOCTL_DISK_GET_MEDIA_TYPES, IntPtr.Zero, 0,
mptr, ssa, ref byret, IntPtr.Zero );
if( ! ok )
{ Console.WriteLine("DeviceIoControl failed"); return; }
int count = byret / ss;
int run = (int) mptr;
DISK_GEOMETRY gem;
for( int i = 0; i < count; i++ )
{
gem = (DISK_GEOMETRY) Marshal.PtrToStructure( (IntPtr) run, ts );
Console.WriteLine( "MediaType={0} SectorsPerTrack={1}", gem.MediaType, gem.SectorsPerTrack );
run += ss;
} Marshal.FreeHGlobal( mptr );
}
}
http://support.microsoft.com/support/kb/articles/Q208/0/48.ASP?LN=EN-US&SD=
gn&FR=0.
// ====================================== MS KB Q115828 =======================
using System.Runtime.InteropServices;internal struct DISK_GEOMETRY
{
public long Cylinders;
public int MediaType;
public int TracksPerCylinder;
public int SectorsPerTrack;
public int BytesPerSector;
}class TestIoCtl
{
[DllImport("kernel32.dll")]
public static extern IntPtr CreateFile(
string lpFileName, int dwDesiredAccess, int dwShareMode,
IntPtr lpSecurityAttributes, int dwCreationDisposition,
int dwFlagsAndAttributes, IntPtr hTemplateFile ); private const int FILE_SHARE_READ = 1;
private const int OPEN_ALWAYS = 4;
private const int INVALID_HANDLE_VALUE = -1;
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern bool DeviceIoControl(
IntPtr hDevice, int dwIoControlCode, IntPtr lpInBuffer, int nInBufferSize,
IntPtr lpOutBuffer, int nOutBufferSize, ref int lpBytesReturned, IntPtr lpOverlapped ); private const int IOCTL_DISK_GET_MEDIA_TYPES = 0x00070c00; static void Main(string[] args)
{
IntPtr hflp = CreateFile( @"\\.\A:", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_ALWAYS, 0, IntPtr.Zero );
if( (int)hflp == INVALID_HANDLE_VALUE )
{ Console.WriteLine("CreateFile failed"); return; } Type ts = typeof( DISK_GEOMETRY );
int ss = Marshal.SizeOf( ts );
int ssa = ss * 20;
IntPtr mptr = Marshal.AllocHGlobal( ssa );
int byret = 0;
bool ok = DeviceIoControl( hflp, IOCTL_DISK_GET_MEDIA_TYPES, IntPtr.Zero, 0,
mptr, ssa, ref byret, IntPtr.Zero );
if( ! ok )
{ Console.WriteLine("DeviceIoControl failed"); return; }
int count = byret / ss;
int run = (int) mptr;
DISK_GEOMETRY gem;
for( int i = 0; i < count; i++ )
{
gem = (DISK_GEOMETRY) Marshal.PtrToStructure( (IntPtr) run, ts );
Console.WriteLine( "MediaType={0} SectorsPerTrack={1}", gem.MediaType, gem.SectorsPerTrack );
run += ss;
} Marshal.FreeHGlobal( mptr );
}
}
http://support.microsoft.com/support/kb/articles/Q208/0/48.ASP?LN=EN-US&SD=
gn&FR=0.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货