I need to do physocal disk reads

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

I want to do something like

where:
m_Device(_T(\\\\.\\PHYSICALDRIVE1) to read drive 1

I then want to read the physical device till the end and save it in a disk
file. Does anyone have an example of doing this in c#. Below are the
pertinate lines from c++. The framework does not appear to support physical
access.

DeviceHandle = CreateFile(m_Device, GENERIC_READ,FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);

then in a loop

rc = ReadFile(DeviceHandle, buffer, sizeof(buffer), &BytesRead, NULL);



__





Jim
 
I am not sure, If I understood the problem correctly. But
if you want to read a file, the here is the code sample.

string path = @"c:\temp\MyTest.txt";

// Open the file to read from.
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}

You would be able to find IO related classed under
System.IO, System.IO.File specifically provide file
manipultion functions.

Thanks,

Muhammad Arif
System Analyst, UHC
-----Original Message-----
I want to do something like

where:
m_Device(_T(\\\\.\\PHYSICALDRIVE1) to read drive 1

I then want to read the physical device till the end and save it in a disk
file. Does anyone have an example of doing this in c#. Below are the
pertinate lines from c++. The framework does not appear to support physical
access.

DeviceHandle = CreateFile(m_Device,
GENERIC_READ,FILE_SHARE_READ, NULL,
 
No physical device access from the IO classes, you need to call the API
using Pinvoke.

Willy.
 
Back
Top