Solved

File restrict, lock.

Posted on 2014-09-26
4
213 Views
Last Modified: 2015-02-12
Delphi XE,

I need to protect some files from deleting, files blong to my user mode application.
Need to put code in service which will protect certain files from delete or modification, but still file must be accessed to my app fully not others.
Please advice.
0
Comment
Question by:Ian Simonv
4 Comments
 
LVL 26

Accepted Solution

by:
Sinisa Vuk earned 250 total points
ID: 40347705
it is quite easy. Just open files in exclusive mode (using fmShareExclusive) on app startup and that is it.
Little problem is what are your files and how your app access them.
...
var
  fs: TFileStream;
  v: byte;
 
begin
  fs := TFileStream.Create('C:\myfile' fmOpenReadWrite or fmShareExclusive);
  try
    fs.Seek(0, soEnd);
....
  finally
    fs.Free;
  end;

Open in new window


more file open flags:
http://www.delphibasics.co.uk/Method.asp?NameSpace=System.IO&Class=File&Type=Class&Method=Open
https://helloacm.com/file-opening-mode-for-tfilestream-in-delphi/


.... inside of your app you can share pointer/handle to opened file.
(pointer for TFileStream or handle for FileOpen function)
0
 
LVL 37

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 250 total points
ID: 40347727
is that while your app is running or also when it's down ?

if also when the app is down, then you'll have to use setup security on the folder containing those files
easiest is to assign access levels to certain groups and then placing the specific accounts in the correct group

you'll network admin for that in a company
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question