2 shmily453397 shmily453397 于 2013.08.29 11:25 提问

c#语言如何读取mbr的信息?

这里是我从网上找的代码。想问为什么用c#读取mbr返回的byte[]为空呢?参数是哪里错了呢?
public const short FILE_ATTRIBUTE_NORMAL = 0x80;
public const short INVALID_HANDLE_VALUE = -1;
public const uint GENERIC_READ = 0x80000000;
public const uint GENERIC_WRITE = 0x40000000;
public const uint CREATE_NEW = 0x00000001;
public const uint CREATE_ALWAYS = 0x00000002;
public const uint OPEN_EXISTING = 3;
public const uint FILE_BEGIN = 0;
public const uint FILE_CURRENT = 1;
public const uint FILE_END = 2;
public static byte[] ReadMBR()
{
//HANDLE hDev=CreateFile("\\.\A:",GENERIC_READ,FILE_SHARE_WRITE,0,OPEN_EXISTING,0,0);

        IntPtr DiskHandle = CreateFile(@"\\.\PhysicalDrive0", GENERIC_READ,
            CREATE_NEW|CREATE_ALWAYS, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero);

        byte[] buffer = new byte[512];
        uint length = 0;
        SetFilePointer(DiskHandle, 0, IntPtr.Zero, FILE_BEGIN);
        ReadFile(DiskHandle, buffer, 512, ref length, IntPtr.Zero);
        CloseHandle(DiskHandle);
        return buffer;  
    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!