Click here to Skip to main content
15,895,142 members

Comments by lokesh.mavale (Top 6 by date)

lokesh.mavale 17-Mar-14 4:08am View    
sir , it is statement in msdn that.. we can use lockfile() to lock bytes which are outside of file range...!!
how can i use dat?
lokesh.mavale 16-Mar-14 2:25am View    
sir, in msdn it is written that it unmounts the drive and only handle will have exlusive access!!
so how can i write in a file which is on unmounted drive?
lokesh.mavale 8-Mar-14 0:16am View    
CreateFile() returns INVALID_HANDLE_VALUE in handle_of_file!!
lokesh.mavale 5-Mar-14 0:20am View    
with referrance to your answer i have tried this :-->


HANDLE hdest,hf;
DWORD b,write;
hdest = CreateFile("\\\\?\\E:",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
NULL,
NULL);

if (hdest == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,TEXT("NOT OK"),TEXT("NOT OK"),0);
}

if (DeviceIoControl( hdest,FSCTL_LOCK_VOLUME,NULL,0,NULL,0,&b,NULL))
{
MessageBox(NULL,TEXT("OK"),TEXT("OK"),0);

hf = CreateFile(TEXT("E:\\M_lucky.txt"), GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hf == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,TEXT("NOT OK AFTER LOCK I"),TEXT("NOT OK AFTRE LOCK"),0);
}
WriteFile(hf, TEXT("M very lucky"), 13, &write, NULL);
}

CloseHandle((HANDLE)hdest);
CloseHandle((HANDLE)hf);

DeviceIoControl( hdest,FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0,&b,NULL);

hf = CreateFile(TEXT("E:\\MNOT_lucky.txt"), GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (hf == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,TEXT("NOT OK AFTER LOCK"),TEXT("NOT OK AFTRE LOCK"),0);

}
WriteFile(hf, TEXT("M lucky"), 8, &write, NULL);
CloseHandle((HANDLE)hf);


""but........""
after getting exclusive lock on E drive, i am unable to create file.
(i have read that : only hdest(HANDLE) gets exclusive lock on that drive. )

here..!!! i want to create M_LUCKY.txt file..!!
(I need EXLUSIVE access on drive with context to PROCESS)
plz help! thanks a lottt!!

is there any other method for doing this??
lokesh.mavale 2-Mar-14 12:07pm View    
thank you sir!! i have read this .. hope that it will work.!