Lazarus

Programming => General => Topic started by: Hansvb on June 15, 2019, 12:33:50 pm

Title: Lock a folder
Post by: Hansvb on June 15, 2019, 12:33:50 pm
Hi, is it possible to lock a folder so that only my own application has free access to the folder content?

Title: Re: Lock a folder
Post by: lucamar on June 15, 2019, 12:38:35 pm
Depends on the OS but usually you have to create a "user", make it the folder's owner and prohibit access to everyone else, which means that to access that folder the application must impersonate that user.

Very basically, the same process that allows a web server (and none else) to access its "documents" folder.
Title: Re: Lock a folder
Post by: Hansvb on June 15, 2019, 02:12:21 pm
It is on windows. I found this:
https://www.freepascal.org/docs-html/rtl/dos/fileattributes.html

I think that is a possible solution.
Title: Re: Lock a folder
Post by: lucamar on June 15, 2019, 05:55:10 pm
It is on windows. I found this:
https://www.freepascal.org/docs-html/rtl/dos/fileattributes.html

I think that is a possible solution.

No, it isn't. Any application can access any file/folder no matter what (standard) attributes you set. Making it have System and/or Hidden attributes just make it a little harder for very naive programs/users (say, absolute beginners).

What you need for Windows, IIRC, is to change the security attributes of the folder, which is another kettle of fish.
Title: Re: Lock a folder
Post by: Thaddy on June 15, 2019, 06:56:48 pm
Correct.