Solved

File restrict, lock.

Posted on 2014-09-26
4
209 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 25

Accepted Solution

by:
Sinisa Vuk earned 250 total points
Comment Utility
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 36

Assisted Solution

by:Geert Gruwez
Geert Gruwez earned 250 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now