473,395 Members | 1,766 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,395 software developers and data experts.

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
Jul 21 '05 #1
3 1267
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

Jul 21 '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.


Jul 21 '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.

Jul 21 '05 #4

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

Similar topics

10
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
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
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
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
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...
3
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....
6
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.