I'm trying to unlock a MO-Drive with DeviceIOControl & FSCTL_UNLOCK_VOLUME.
But I always get an error.
GetLastError() says 6 = The handle is invalid (ERROR_INVALID_HANDLE) !
I'm getting the handle with the CreateFile() funciton like this:
h=CreateFile(argv[1],0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0
,NULL);
I tried these values for argv[1]:
\\.\F:
\\\\.\\F:
\\.\\PhysicalDrive0
\\.\PHYSICALDRIVE0
\\\\.\\PhysicalDrive0
and so on.... :(
The Example
(http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/winbase/fil
esio_7wmd.htm) from the Microsoft-Site runs good, but mine isn't :( !
Why is the volumename described on the MSDN-Site (
lpFileName=\\.\PHYSICALDRIVEn) is other than in the Example
above(lpFileName=\\\\.\\PhysicalDrive0) ?
I also tried to lock the drive with FSCTL_LOCK_VOLUME before unlocking, but
that fails with the same errorcode!
Why do I always get an error ? Can somebody PLEASE help me ????
Thank you.
Bye,
Sashi
Does CreateFile succeed? What is the value of h? If it's
INVALID_HANDLE_VALUE, it failed. Then check error code. You may have to open
volume with GENERIC_READ and GENERIC_WRITE access.
--
JMu
"Sashi Asokarajan" <sa...@gmx.de> wrote in message
news:987773692.328094@sisapint06...
first of all, thank you for your reply!
the value of h is !INVALID_HANDLE_VALUE. createfile succeeds!
But all my calls to the deviceioctrol fails with the invalid handle error !
this is my code:
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
int main(int argc, char *argv[])
{
HANDLE h;
BOOL b;
DWORD dw=0;
OVERLAPPED ov;
printf("Opening %s...\n",argv[1]);
h=CreateFile(argv[1],0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0
,NULL);
b=DeviceIoControl(h,FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0,&dw,&ov);
if (b)
printf("UNLOCKED!");
else
{
printf("DeviceIoControl(FSCTL_UNLOCK_VOLUME) ERROR: %d",GetLastError());
CloseHandle(h);
return 1;
}
CloseHandle(h);
return 0;
}
--
JMu
"Sashi Asokarajan" <sa...@gmx.de> wrote in message
news:988010315.654197@sisapint06...
first of all thank you very much for your support!
I tried to replace &ov with 0 then (OVERLAPPED)NULL, NULL and
I always get the Errorcode:87 (ERROR_INVALID_PARAMETER) !
Do you have any idea ?
Thanks again for your support!
Bye,
Sashi
Try calling CreateFile with an access of at least
GENERIC_READ (instead of 0) or use
GENERIC_READ|GENERIC_WRITE
access.
.
Joe
> Try calling CreateFile with an access of at least
> GENERIC_READ (instead of 0) or use
> GENERIC_READ|GENERIC_WRITE
that also fails!
bye