JLW,
how do you declare CreateFile?
Here is working sample - I tried it calling TF (@"\\.\PHYSICALDRIVE0") -
note @ before string and see function defnition below. I don't have tape -
ughhh!
Sample uses some prototypes from
www.pinvoke.net - thank you guys!
public static int CREATE_NEW = 1;
public static int CREATE_ALWAYS = 2;
public static int OPEN_EXISTING = 3;
public static int OPEN_ALWAYS = 4;
public static int TRUNCATE_EXISTING = 5;
[DllImport("kernel32.dll", SetLastError=true)]
static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool CloseHandle(IntPtr hObject);
private static void TF(string filename) {
IntPtr ptr = CreateFile(filename,0, 0,IntPtr.Zero, (uint)OPEN_EXISTING,0,
IntPtr.Zero);
/* Is bad handle? INVALID_HANDLE_VALUE */
if (ptr.ToInt32() == -1)
{
/* ask the framework to marshall the win32 error code to an exception */
Console.WriteLine(String.Format("{0}",Marshal.GetLastWin32Error()));
}
else
{
Console.WriteLine("Opened");
CloseHandle(ptr);
}
}
HTH
Alex
"JLW" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> With that, the handle comes back as -1 every time, regardless of what I
> specify as the "file". I have seen this work under VB6, which is why it's
> soo damned frustraiting that it can't be done under the framework.
>
> Thanks,
> JLW
> "AlexS" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > Hi, JLW
> >
> > you might need to use Win32 API CreateFile - see full description in
> > Platform SDK help or on MSDN.
> > I think .Net has some limitations, which files could be opened through
> > standard framework methods.
> >
> > HTH
> > Alex
> >
> > "JLW" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Actually, I'm trying to open the drive itself. I know it sounds
crazy,
> > but
> > > I'm concentrating on the \\.\TAPE0 one first, so I can make a backup
> > program
> > > that won't cost me a few thousand bucks. The first one will return me
a
> > > handle, but for the TAPE0, I get no handle. I switched to using
> File.Open
> > > and that seems to help a bit. I want to be able top open the
harddrive
> at
> > a
> > > low level so that I can also make myself a low-level formatter
> (Zero-Fill
> > > drive).
> > >
> > > Thanks,
> > > JLW
> > > "Mike" <(E-Mail Removed)> wrote in message
> > > news:%(E-Mail Removed)...
> > > > are you getting an error message when you try to create the file on
> the
> > > > drive>?
> > > > "JLW" <(E-Mail Removed)> wrote in message
> > > > news:(E-Mail Removed)...
> > > > > I cannot get this to work correctly:
> > > > >
> > > > > File.Create("\\.\PHYSICALDRIVE0")
> > > > > or
> > > > > File.Create("\\.\Tape0")
> > > > >
> > > > >
> > > > > I've been searching for the better part of a week for this one.
> > > > >
> > > > > Thanks,
> > > > > JLW
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>