Controlling Access To Temporary File
-
My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time
-
My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time
1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. Probable solution: You need to put some sort of file encryption algo so that only authorize process/program can open it to read/write data from/into the file. but one draw back there in this. anyone can corrupt the file and data will be lost beyound recovery. 2. A tmp files can be deleted by a countom made software that looks for special file name patters and if found can take appropriate action of deletion.. this SW can be put to start during Windows startup so that by teh time PC is ready to be used all tmp files are deleted. 2. B also tmp file names can be logged in one common file with complete path. this file can be opened by a SW during Windows startup and all entries in that file can be deleted one by one. tmp file paths will be added to this log file by various processes/programs that require peroidic/auto deletion of log files. techi !!
-
1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. Probable solution: You need to put some sort of file encryption algo so that only authorize process/program can open it to read/write data from/into the file. but one draw back there in this. anyone can corrupt the file and data will be lost beyound recovery. 2. A tmp files can be deleted by a countom made software that looks for special file name patters and if found can take appropriate action of deletion.. this SW can be put to start during Windows startup so that by teh time PC is ready to be used all tmp files are deleted. 2. B also tmp file names can be logged in one common file with complete path. this file can be opened by a SW during Windows startup and all entries in that file can be deleted one by one. tmp file paths will be added to this log file by various processes/programs that require peroidic/auto deletion of log files. techi !!
BhaskarBora wrote: 1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. What rubbish. See the dwShareMode param of CreateFile(). http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] 2. This is trying to clean up after the fact. Far better to prevent the problem in the first place. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
My questions are these; How can I ensure that a program which creates a file is the only one allowed to access that file? And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? Taking into consideration that the program which created the file has some sort of security lock on the file. Something clever should be said, but I don't have the time
Raggamuffin wrote: How can I ensure that a program which creates a file is the only one allowed to access that file? See the dwShareMode param of CreateFile(). Sharemode can be also spec'd in some other functions that wrap CreateFile(). See: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] Raggamuffin wrote: And furthermore how can I make windows clean up my temporary files (in case the program crashes or something)? 1) Use C++ and/or Structured Exception Handling (SEH). There are several good articles here on CP about Exception Handling. 2) Use RAII to manage the file handle and simply rely on destructors to cleanup for you. Boost scoped_ptr will do this for you very nicely. See: http://www.boost.org/libs/smart_ptr/scoped_ptr.htm[^] Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
-
BhaskarBora wrote: 1. you can't do it directly in Windows. Windows does not support file locking or access validity of any form. Only access level rights of a file are checked while accessing a file, which comes from the current user's access rights and privileges. What rubbish. See the dwShareMode param of CreateFile(). http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/createfile.asp[^] 2. This is trying to clean up after the fact. Far better to prevent the problem in the first place. Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
"What rubbish. See the dwShareMode param of CreateFile(). " CreateFile will work till you have opened the file and after u close it any process can open it and read the contents. requirement is that no other process should be able to even open or read the file, which was originally created by some other process. this can be done by encrypting the file whose descryption is known to only the creator of the file. _________________________________________________________________ "Think big, think fast, think ahead. Ideas are no one's monopoly"