Making a file not accessible by other applications
-
i am working an application that uses a file for some purpose. i am creating that file by using
CreateFile()
function. Now, i want to make sure that no other application uses that File till me application closes. i.e, i want no other application to access the file (not even for reading) as long as my application is running. how can i do this?Regards, Srinivas
-
i am working an application that uses a file for some purpose. i am creating that file by using
CreateFile()
function. Now, i want to make sure that no other application uses that File till me application closes. i.e, i want no other application to access the file (not even for reading) as long as my application is running. how can i do this?Regards, Srinivas
Use
dwShareMode
asNULL
while usingCreateFile
API.Prasad Notifier using ATL | Operator new[],delete[][^]
-
i am working an application that uses a file for some purpose. i am creating that file by using
CreateFile()
function. Now, i want to make sure that no other application uses that File till me application closes. i.e, i want no other application to access the file (not even for reading) as long as my application is running. how can i do this?Regards, Srinivas
-
Use
dwShareMode
asNULL
while usingCreateFile
API.Prasad Notifier using ATL | Operator new[],delete[][^]
No, it is not working for me. i don't know what mistake i am doing. here is the sample code of what i have written
hFile = CreateFile ( strFileName,GENERIC_WRITE ,NULL,NULL,CREATE_ALWAYS ,FILE_ATTRIBUTE_NORMAL,NULL);
after creation of the file, i write the data to that file. now i dont want any other application to access that File till i close my application. how can i do this? thanks..Regards, Srinivas
-
No, it is not working for me. i don't know what mistake i am doing. here is the sample code of what i have written
hFile = CreateFile ( strFileName,GENERIC_WRITE ,NULL,NULL,CREATE_ALWAYS ,FILE_ATTRIBUTE_NORMAL,NULL);
after creation of the file, i write the data to that file. now i dont want any other application to access that File till i close my application. how can i do this? thanks..Regards, Srinivas
vasu_sri wrote:
No, it is not working for me.
How you are verifying this.
vasu_sri wrote:
now i dont want any other application to access that File till i close my application.
Yes, by above code, no other application could access the file, till handle is closed.
vasu_sri wrote:
how can i do this?
Its already shown.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
i am working an application that uses a file for some purpose. i am creating that file by using
CreateFile()
function. Now, i want to make sure that no other application uses that File till me application closes. i.e, i want no other application to access the file (not even for reading) as long as my application is running. how can i do this?Regards, Srinivas
HANDLE hFile = CreateFile( psFile, GENERIC\_READ | GENERIC\_WRITE, 0, // No sharing NULL, OPEN\_EXISTING, FILE\_ATTRIBUTE\_NORMAL, NULL); DWORD dwErr = GetLastError(); // NOTE: Error 5 likely indicates file is marked read-only
...
CloseHandle(hFile); // Unlock it