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. how to protect files like this?

how to protect files like this?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionannouncement
7 Posts 4 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.
  • S Offline
    S Offline
    szcococut
    wrote on last edited by
    #1

    I have a file (d://*.txt) require : 1.My app(exe) can read ,write ,delete ,update this file; 2.user(you or me) can't write ,update ,delete this file,but he can read this file. can you give me advise please? thanks

    K D 2 Replies Last reply
    0
    • S szcococut

      I have a file (d://*.txt) require : 1.My app(exe) can read ,write ,delete ,update this file; 2.user(you or me) can't write ,update ,delete this file,but he can read this file. can you give me advise please? thanks

      K Offline
      K Offline
      khan
      wrote on last edited by
      #2

      Open the file in read-only mode, and keep it open. That way no one can write to, or delete the file. When you need to write to it, or update it or delete it, close the file handle, then do whatever you want with it. Have fun. this is this.

      T 1 Reply Last reply
      0
      • K khan

        Open the file in read-only mode, and keep it open. That way no one can write to, or delete the file. When you need to write to it, or update it or delete it, close the file handle, then do whatever you want with it. Have fun. this is this.

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        won't work anymore when closing the application


        TOXCCT >>> GEII power
        [toxcct][VisualCalc]

        K 1 Reply Last reply
        0
        • T toxcct

          won't work anymore when closing the application


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          K Offline
          K Offline
          khan
          wrote on last edited by
          #4

          Can use a service for that instead of a program. this is this.

          T 1 Reply Last reply
          0
          • K khan

            Can use a service for that instead of a program. this is this.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            not a good method. there's no need to use memory and processor ressources... NTFS provides rights on the file system, which allow you to set who can and who cannot access the file/directory, and how wide is the authorization for one on that file...


            TOXCCT >>> GEII power
            [toxcct][VisualCalc]

            K 1 Reply Last reply
            0
            • T toxcct

              not a good method. there's no need to use memory and processor ressources... NTFS provides rights on the file system, which allow you to set who can and who cannot access the file/directory, and how wide is the authorization for one on that file...


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              K Offline
              K Offline
              khan
              wrote on last edited by
              #6

              I don't know if it is possible to set access rights for individual programs in NTFS ("not different users"). Like: one program can read modify/delete a file while another cannot? Maybe you can link to the right source. this is this.

              1 Reply Last reply
              0
              • S szcococut

                I have a file (d://*.txt) require : 1.My app(exe) can read ,write ,delete ,update this file; 2.user(you or me) can't write ,update ,delete this file,but he can read this file. can you give me advise please? thanks

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #7

                To expand on toxcct's suggestion. Deny all access to the file except for one user (a user that is not used by any person). Then in your program, impersonate that user before trying to update the file. See CreateProcessWithLogonW(). Make sense?


                "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

                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