I need to do physocal disk reads

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
 
M

Muhammad Arif

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,
 
W

Willy Denoyette [MVP]

No physical device access from the IO classes, you need to call the API
using Pinvoke.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top