473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CreateFile Sector/Block level equivalent

Hello all,

What is the equivalent in the .NET Framework for accessing
a device at the block/sector level such as one would when
using CreateFile on a device like "\\.\D:"? Attempting to create
a BinaryReader on a FileStream opened (read-only) on "D:"
yields an Access Denied exception.

Thanks,

- Scott

Aug 30 '06 #1
3 2843
Scott Bell wrote:
Hello all,

What is the equivalent in the .NET Framework for accessing
a device at the block/sector level such as one would when
using CreateFile on a device like "\\.\D:"? Attempting to create
a BinaryReader on a FileStream opened (read-only) on "D:"
yields an Access Denied exception.
Use P/Invoke to call CreateFile and ReadFile directly passing in the
appropriate options to open a device.

http://www.pinvoke.net/default.aspx/...reateFile.html
http://www.pinvoke.net/default.aspx/.../ReadFile.html

-cd
Aug 30 '06 #2

"Carl Daniel [VC++ MVP]" <cp*****************************@mvps.org.nospam >
wrote in message news:uD**************@TK2MSFTNGP06.phx.gbl...
| Scott Bell wrote:
| Hello all,
| >
| What is the equivalent in the .NET Framework for accessing
| a device at the block/sector level such as one would when
| using CreateFile on a device like "\\.\D:"? Attempting to create
| a BinaryReader on a FileStream opened (read-only) on "D:"
| yields an Access Denied exception.
|
| Use P/Invoke to call CreateFile and ReadFile directly passing in the
| appropriate options to open a device.
|
| http://www.pinvoke.net/default.aspx/...reateFile.html
| http://www.pinvoke.net/default.aspx/.../ReadFile.html
|
| -cd
|
|

Note that there is no need to Pinvoke Win32's ReadFile, the handle (use a
SafeHandle in V2) returned by CreateFile can be used to create a FileStream,
this class has a number of contructor overloads that take an IntPtr
(representing the handle) or a SafeHandle.

Willy.
Aug 31 '06 #3
Willy,

Thanks, the following worked out to be the most ideal:

[DllImport("Kernel32.dll", SetLastError = true, CharSet =
CharSet.Auto)]
static extern SafeFileHandle CreateFile(
string fileName,
[MarshalAs(UnmanagedType.U4)] FileAccess fileAccess,
[MarshalAs(UnmanagedType.U4)] FileShare fileShare,
int securityAttributes,
[MarshalAs(UnmanagedType.U4)] FileMode creationDisposition,
int flags,
IntPtr template);

- Scott

Willy Denoyette [MVP] wrote:
Note that there is no need to Pinvoke Win32's ReadFile, the handle (use a
SafeHandle in V2) returned by CreateFile can be used to create a FileStream,
this class has a number of contructor overloads that take an IntPtr
(representing the handle) or a SafeHandle.

Willy.
Aug 31 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chuck Rittersdorf | last post by:
Hi There I am having a problem using the win32 API from VB6. I am trying to send a command string to a printer(zebra TLP 2742) on LPT1 using the folowing API functions CreateFile and...
14
by: laurence | last post by:
I am implementing a comprehensive image-map generator utility, so have been studying W3C HTML 4.01 Specification (http://www.w3.org/TR/html4/struct/objects.html#h-13.6) on image maps (among other...
7
by: Claudio Grondi | last post by:
Googling for keywords like "direct access sector harddrive Python module Windows" seems to give no useful results. Any hints(best if cross-platform)? Claudio
4
by: craigkenisston | last post by:
Hi, How can I open a file with the FILE_FLAG_NO_BUFFERING using .net just like in the win32 days ?
8
by: Stephen Remde | last post by:
Hi, Private Declare Function CreateFile _ Lib "kernel32" Alias "CreateFileA" _ (ByVal lpFileName As String, _ ByVal dwDesiredAccess As Long, _ ByVal dwShareMode As Long, _ ByVal...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
2
by: Jim Flanagan | last post by:
Hi... I am using VB.net Express to experiment with the Win32 API functions that are available. The current project is an application that will read the raw sectors of a logical drive so that a...
1
by: Joe B. | last post by:
I have been wading through using SetupDi... API to get a device path to use in CreateFile so that I could open a USB HID device. I can now get a device path, but when I try to open for...
7
by: GTalbot | last post by:
Hello fellow authoring.stylesheets colleagues, Can someone please explain why the bottom margin of the last inflow block-level child in an overflowed parent should not have its margin reachable....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.