Could someone help with this one?

  • Thread starter Thread starter JLW
  • Start date Start date
J

JLW

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
 
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
 
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
 
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
 
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
 
Though I'll probably never use this, did want to ask a question about the
tape drive and how it works with windows.

By using the UNC path to the tape drive does windows automatically take care
of all the IO functions(i.e. rewinding the tape, forwarding the tape to the
proper position). My knowledge on how tape drives actually work with the
system is rather limited, just wanted to know if that functionality was
already built into windows or not

Thanks,
CJ
 
Supposidly it is, but there's very little documentation on it, and the
Platform SDK really sucks on the subject.
I'm going to give another shot at it later today and will post back what
I've been able to figure out to date.

JLW
 
Back
Top