473,508 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open diskpartition

Something went wrong with my previous post, so this is the full question :

Hello,

in the past I used the CreateFile, ReadFile and WriteFile api to access
a diskpartition directly (e.g. "\\.\c:") to read raw sectors. I was
planning on converting some of those old c++ classes to c#. However
using FileStream I get the following error :

"Additional information: FileStream opent geen Win32-apparaten zoals
schijfpartities en tapestations. Maak geen gebruik van \\.\ in het pad."

which translates into

"Additional information: FileStream doesn't open Win32-systems like
diskpartitions and tapestations. Don't use \\.\ in the path."

So I need to use another class but I can't find out which one. Or isn't
there one and am I still stuck with the old win32 API which I need to
access through P/Invoke?

TIA

Yves
Nov 16 '05 #1
3 1379
Yves,

You can still use the FileStream class. What you want to do is call the
CreateFile API function to get a handle to the partition. Once you do that,
you can pass the handle to the constructor of the FileStream object, and
then use it as you would normally.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Yves Dhondt" <no@privacy.net> wrote in message
news:41*********************@news.skynet.be...
Something went wrong with my previous post, so this is the full question :

Hello,

in the past I used the CreateFile, ReadFile and WriteFile api to access
a diskpartition directly (e.g. "\\.\c:") to read raw sectors. I was
planning on converting some of those old c++ classes to c#. However
using FileStream I get the following error :

"Additional information: FileStream opent geen Win32-apparaten zoals
schijfpartities en tapestations. Maak geen gebruik van \\.\ in het pad."

which translates into

"Additional information: FileStream doesn't open Win32-systems like
diskpartitions and tapestations. Don't use \\.\ in the path."

So I need to use another class but I can't find out which one. Or isn't
there one and am I still stuck with the old win32 API which I need to
access through P/Invoke?

TIA

Yves

Nov 16 '05 #2
Thanks for your reply, I tried doing that but I keep running into a
System.IO.IOException when I try to create the FileStream complaining
about an invalid parameter. I attached the example code below.

Also as a side note, the CreateFile doesn't seem to like volumes (hard
disk). Disk stations, cd/dvd-drives and all other kind of media work all
right (using tests with ReadFile API in stead of the FileStream).

Yves

======== CODE LISTING BEGIN ========

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;

class Test {
[DllImport("kernel32", SetLastError=true)]
static extern unsafe IntPtr CreateFile(
string FileName, // file name
uint DesiredAccess, // access mode
uint ShareMode, // share mode
uint SecurityAttributes, // Security Attributes
uint CreationDisposition, // how to create
uint FlagsAndAttributes, // file attributes
int hTemplateFile // handle to template file
);

public static int Main(string[] args)
{
String the_drive = @"\\.\A:"; // DOESN'T WORK WITH C-DRIVE
IntPtr handle = CreateFile(
the_drive,
0x80000000 | 0x40000000, // GENERIC_READ | GENERIC_WRITE
0x1 | 0x2, // FILE_SHARE_READ | FILE_SHARE_WRITE
0,
3, // OPEN_EXISTING
0,
0);

FileStream fs = new FileStream(handle, FileAccess.ReadWrite);

return 0;
}
}

======== CODE LISTING END ========

Nicholas Paldino [.NET/C# MVP] wrote:
Yves,

You can still use the FileStream class. What you want to do is call the
CreateFile API function to get a handle to the partition. Once you do that,
you can pass the handle to the constructor of the FileStream object, and
then use it as you would normally.

Hope this helps.


Nov 16 '05 #3
Yves Dhondt wrote:
Thanks for your reply, I tried doing that but I keep running into a
System.IO.IOException when I try to create the FileStream complaining
about an invalid parameter. I attached the example code below.

Also as a side note, the CreateFile doesn't seem to like volumes (hard
disk). Disk stations, cd/dvd-drives and all other kind of media work all
right (using tests with ReadFile API in stead of the FileStream).
I solved this one. The ones I tested it with didn't have FILE_SHARE_READ
| FILE_SHARE_WRITE constants set correctly.

Yves

======== CODE LISTING BEGIN ========

using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;

class Test {
[DllImport("kernel32", SetLastError=true)]
static extern unsafe IntPtr CreateFile(
string FileName, // file name
uint DesiredAccess, // access mode
uint ShareMode, // share mode
uint SecurityAttributes, // Security Attributes
uint CreationDisposition, // how to create
uint FlagsAndAttributes, // file attributes
int hTemplateFile // handle to template file
);

public static int Main(string[] args)
{
String the_drive = @"\\.\A:"; // DOESN'T WORK WITH C-DRIVE
IntPtr handle = CreateFile(
the_drive,
0x80000000 | 0x40000000, // GENERIC_READ | GENERIC_WRITE
0x1 | 0x2, // FILE_SHARE_READ | FILE_SHARE_WRITE
0,
3, // OPEN_EXISTING
0,
0);

FileStream fs = new FileStream(handle, FileAccess.ReadWrite);

return 0;
}
}

======== CODE LISTING END ========

Nicholas Paldino [.NET/C# MVP] wrote:
Yves,

You can still use the FileStream class. What you want to do is
call the
CreateFile API function to get a handle to the partition. Once you do
that,
you can pass the handle to the constructor of the FileStream object, and
then use it as you would normally.

Hope this helps.

Nov 16 '05 #4

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

Similar topics

3
1269
by: Yves Dhondt | last post by:
Something went wrong with my previous post, so this is the full question : Hello, in the past I used the CreateFile, ReadFile and WriteFile api to access a diskpartition directly (e.g....
10
11193
by: Marshall Dudley | last post by:
When I do the following line in Netscape, the popup loads as it should, but the parent window usually, but not always, reloads as well. <a href="#"...
10
6708
by: David McCulloch | last post by:
The following code opens a new window, but the "resizeTo" doesn't resize it. Why not? (Don't ask why I simply did not open the window with the new size....my original problem was how to open a...
3
24665
by: NeverLift | last post by:
But, if it's not open, I don't want to open it . . . using window.open will open it if it doesn't exist, even if the url in that open is null (the window is then empty -- but it's open). The...
5
10580
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
1
2559
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
6
3612
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
6
10019
by: qysbc | last post by:
I have a web page and there is a link to open a TIFF file. The way I do it is to have the server code open a binary stream, set the content type to "image/tiff" and call Response.BinaryWrite. On...
0
12004
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1553
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.