Ata
Ata

Reputation: 12544

how to lock filename

how to lock filename , so windows users can not change File filename .

Upvotes: 1

Views: 3619

Answers (3)

Bob Harvey
Bob Harvey

Reputation: 9

Think outside the box - use Alternative data streams.

Hide the filename you want in there & have a background task to locate ads with your data stream and restore the 'correct' file name.

Thats not foolproof either, if the user moves the file to a fat32 volume & back again your ads will be lost.

Think outside the box - write your own file system and install it as an ifs


Think outside the box - don't put your data in a file, put it in a database


Think outside the box - Trust your users

This is what most of us do. Helpful error messages at start-up, graceful recovery, perhaps a file dialogue so the user can choose a filename that suits them for reasons you havn't anticipated.

Upvotes: 0

Nayan
Nayan

Reputation: 3214

Two ways:

  • Use the security permissions to restrict the user from doing so.
  • Open the file in exclusive mode, denying any operation on it by any other app.

Unfortunately, none of them is fail-proof... for the good of humanity :)

Upvotes: 4

Paweł Dyda
Paweł Dyda

Reputation: 18662

Thank God, this is not possible. You may restrict access to this file, so the user won't be able to access it and thus modify its name, but otherwise you cannot prevent them from renaming files.

One more thing, though...

If the file is continuously open in exclusive mode, nobody else will able to modify it, i.e. change its name... But this mean that some process has to lock it, i.e. windows service. Closing such service or killing the process in other way will release the lock.

Upvotes: 2

Related Questions