Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [CLARIFIED]Is it possible to lock a file from deletion?

[CLARIFIED]Is it possible to lock a file from deletion?

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelpquestion
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chandu004
    wrote on last edited by
    #1

    hai all, i want to know, if it is possible to lock a file, such that, nobody can delete it. why i want this is, for my application, iam using file as the database, where all the user data and other data is available. i remember that, long back, i used to lock a file from dosmode using ren command. but now iam unable to recall it. can any body remind that logic to me and also if this could be applied to solve my problem? thanks.

    M 1 Reply Last reply
    0
    • C chandu004

      hai all, i want to know, if it is possible to lock a file, such that, nobody can delete it. why i want this is, for my application, iam using file as the database, where all the user data and other data is available. i remember that, long back, i used to lock a file from dosmode using ren command. but now iam unable to recall it. can any body remind that logic to me and also if this could be applied to solve my problem? thanks.

      M Offline
      M Offline
      Matthew Faithfull
      wrote on last edited by
      #2

      The C runtime provides a _lock_file[^] function. You might just want to use permissions to deny your users delete authority on the file though. Probably a safer solution.

      Nothing is exactly what it seems but everything with seems can be unpicked.

      C 2 Replies Last reply
      0
      • M Matthew Faithfull

        The C runtime provides a _lock_file[^] function. You might just want to use permissions to deny your users delete authority on the file though. Probably a safer solution.

        Nothing is exactly what it seems but everything with seems can be unpicked.

        C Offline
        C Offline
        chandu004
        wrote on last edited by
        #3

        thanks for your response. but what i understood from msdn is, file will be locked for the other processes. what i want is, i should not be able to delete it from windows. can you just guide me.

        Matthew Faithfull wrote:

        You might just want to use permissions to deny your users delete authority on the file though

        can you just explain me how to do it? thank you.

        M J 2 Replies Last reply
        0
        • M Matthew Faithfull

          The C runtime provides a _lock_file[^] function. You might just want to use permissions to deny your users delete authority on the file though. Probably a safer solution.

          Nothing is exactly what it seems but everything with seems can be unpicked.

          C Offline
          C Offline
          chandu004
          wrote on last edited by
          #4

          do you remember how to do a dos lock, some clues i could recall. we used something like >ren [filename] [alt+some numbers] some thing we used to do. but now it is not working. can you guide me in this regard also. thank you.

          1 Reply Last reply
          0
          • C chandu004

            thanks for your response. but what i understood from msdn is, file will be locked for the other processes. what i want is, i should not be able to delete it from windows. can you just guide me.

            Matthew Faithfull wrote:

            You might just want to use permissions to deny your users delete authority on the file though

            can you just explain me how to do it? thank you.

            M Offline
            M Offline
            Matthew Faithfull
            wrote on last edited by
            #5

            In this regard Windows counts as 'another process'. I have no idea of any DOS locking tricks and I doubt they have carried over to NTFS anyway. User permission is really a sysadmin thing, you need to look at the accounts and groups of users you have on your system and talk to whoever manages it about how to secure your database against deletion.

            Nothing is exactly what it seems but everything with seems can be unpicked.

            C 1 Reply Last reply
            0
            • M Matthew Faithfull

              In this regard Windows counts as 'another process'. I have no idea of any DOS locking tricks and I doubt they have carried over to NTFS anyway. User permission is really a sysadmin thing, you need to look at the accounts and groups of users you have on your system and talk to whoever manages it about how to secure your database against deletion.

              Nothing is exactly what it seems but everything with seems can be unpicked.

              C Offline
              C Offline
              chandu004
              wrote on last edited by
              #6

              thanks again for your explanation. now i understood that, my system administrator can do something at my clients place to achieve my task. but can you confirm that, though the folder or file is locked for deletion, still, my program can update the file? thank you.

              M 1 Reply Last reply
              0
              • C chandu004

                thanks again for your explanation. now i understood that, my system administrator can do something at my clients place to achieve my task. but can you confirm that, though the folder or file is locked for deletion, still, my program can update the file? thank you.

                M Offline
                M Offline
                Matthew Faithfull
                wrote on last edited by
                #7

                Yes under modern Windows systems Delete/Create/Read/Write etc permissions are separate, you can allow or any combination to any user or group of users. You might need to specify which user your program runs as depending on the way the site is configured. A program can be launched with the permission sof a specific user and impersonates that user when it comes to getting file access. Your sysadmin could for example create a SpecialDatabaseUser user who has exclusive rights to the database itself and your program could be made to act as that user. There are lots of options and different sites may require different things but I think this approach is the most likely to succeed for deleteion prevention, 'sharing' is of course another issue altogether.:)

                Nothing is exactly what it seems but everything with seems can be unpicked.

                C 1 Reply Last reply
                0
                • C chandu004

                  thanks for your response. but what i understood from msdn is, file will be locked for the other processes. what i want is, i should not be able to delete it from windows. can you just guide me.

                  Matthew Faithfull wrote:

                  You might just want to use permissions to deny your users delete authority on the file though

                  can you just explain me how to do it? thank you.

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #8

                  chandu004 wrote:

                  what i want is, i should not be able to delete it from windows.

                  I personally would be extremely annoyed by a file on my I could not delete. I would insert considerable energy in *getting* it deleted - up until formatting and reinstall, because I would immediatly suspect either a trojan or SONY and its infamous rootkits behind that. Tweaking permissions is OK, though. I *COULD* technically get the rights to delete the file, but the file has "Do not delete me!" printed in big red letters on the surface.


                  Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
                  Douglas Adams, "Dirk Gently's Holistic Detective Agency"

                  1 Reply Last reply
                  0
                  • M Matthew Faithfull

                    Yes under modern Windows systems Delete/Create/Read/Write etc permissions are separate, you can allow or any combination to any user or group of users. You might need to specify which user your program runs as depending on the way the site is configured. A program can be launched with the permission sof a specific user and impersonates that user when it comes to getting file access. Your sysadmin could for example create a SpecialDatabaseUser user who has exclusive rights to the database itself and your program could be made to act as that user. There are lots of options and different sites may require different things but I think this approach is the most likely to succeed for deleteion prevention, 'sharing' is of course another issue altogether.:)

                    Nothing is exactly what it seems but everything with seems can be unpicked.

                    C Offline
                    C Offline
                    chandu004
                    wrote on last edited by
                    #9

                    :-Dthanks again.

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups