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. File with permission

File with permission

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
8 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.
  • V Offline
    V Offline
    vivekphlp
    wrote on last edited by
    #1

    Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.

    Proud To Be an India

    P U S 3 Replies Last reply
    0
    • V vivekphlp

      Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.

      Proud To Be an India

      P Offline
      P Offline
      Paresh Chitte
      wrote on last edited by
      #2

      Do you mean a simple text file written through VC++ / C++ code ? If this is your requirement then try _chmod, _wchmod. Regards, Paresh.

      V 1 Reply Last reply
      0
      • P Paresh Chitte

        Do you mean a simple text file written through VC++ / C++ code ? If this is your requirement then try _chmod, _wchmod. Regards, Paresh.

        V Offline
        V Offline
        vivekphlp
        wrote on last edited by
        #3

        I have a program running under USER mode - and later i have to create a file in administrator mode - setting the privilages and all... Hope u got my requirement now..

        Proud To Be an Indian

        P 1 Reply Last reply
        0
        • V vivekphlp

          Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.

          Proud To Be an India

          U Offline
          U Offline
          uday kiran janaswamy
          wrote on last edited by
          #4

          Hi, Check with SetFileAttribute(...) Api. It will Help You.

          Uday kiran

          1 Reply Last reply
          0
          • V vivekphlp

            I have a program running under USER mode - and later i have to create a file in administrator mode - setting the privilages and all... Hope u got my requirement now..

            Proud To Be an Indian

            P Offline
            P Offline
            Paresh Chitte
            wrote on last edited by
            #5

            Try using API SetFileSecurity. Regards, Paresh.

            P 1 Reply Last reply
            0
            • P Paresh Chitte

              Try using API SetFileSecurity. Regards, Paresh.

              P Offline
              P Offline
              Paresh Chitte
              wrote on last edited by
              #6

              Try also using SetNamedSecurityInfo. Regards, Paresh.

              1 Reply Last reply
              0
              • V vivekphlp

                Can any one plz help me to create a file IN VC++ or C++ that can be given some FILE permissions (READ for normal users).The files cannot be deleted also.

                Proud To Be an India

                S Offline
                S Offline
                skornel
                wrote on last edited by
                #7

                I was having the same issue. When the ini file was created by someone in the administrators group, the file was only accessible by others in the administrators group. 'Normal' users were denied permission. So I changed the fourth parameter in the CreateFile() function call to be: m_hFile = CreateFile(..., ..., ..., GetSAForEveryone(), ..., 0, 0); SECURITY_ATTRIBUTES* GetSAForEveryone() { static SECURITY_ATTRIBUTES SA; static SECURITY_DESCRIPTOR SD; static bool FirstTime(true); if (FirstTime) { SD.Revision = SECURITY_DESCRIPTOR_REVISION; SD.Sbz1 = 0; // reserved SD.Control = SE_DACL_PRESENT; SD.Owner = 0; SD.Group = 0; SD.Sacl = 0; SD.Dacl = 0; // This grants access to everyone SA.nLength = sizeof(SECURITY_ATTRIBUTES); SA.bInheritHandle = false; SA.lpSecurityDescriptor = &SD; FirstTime = false; } return &SA; } This works great. The file is created so that everyone on the machine can read/write/delete/copy/move it. However, the next hurdle you will face is that if a user in the administrators group copies/moves the file to another folder, the file is again not accessible by all users. To get around this issue I found a page (http://support.microsoft.com/kb/310316) that addresses the issue. The bottom line is that I set the registry entry mentioned in that article for each user that creates the file. This may not be an acceptable solution in your case but it works for me.

                V 1 Reply Last reply
                0
                • S skornel

                  I was having the same issue. When the ini file was created by someone in the administrators group, the file was only accessible by others in the administrators group. 'Normal' users were denied permission. So I changed the fourth parameter in the CreateFile() function call to be: m_hFile = CreateFile(..., ..., ..., GetSAForEveryone(), ..., 0, 0); SECURITY_ATTRIBUTES* GetSAForEveryone() { static SECURITY_ATTRIBUTES SA; static SECURITY_DESCRIPTOR SD; static bool FirstTime(true); if (FirstTime) { SD.Revision = SECURITY_DESCRIPTOR_REVISION; SD.Sbz1 = 0; // reserved SD.Control = SE_DACL_PRESENT; SD.Owner = 0; SD.Group = 0; SD.Sacl = 0; SD.Dacl = 0; // This grants access to everyone SA.nLength = sizeof(SECURITY_ATTRIBUTES); SA.bInheritHandle = false; SA.lpSecurityDescriptor = &SD; FirstTime = false; } return &SA; } This works great. The file is created so that everyone on the machine can read/write/delete/copy/move it. However, the next hurdle you will face is that if a user in the administrators group copies/moves the file to another folder, the file is again not accessible by all users. To get around this issue I found a page (http://support.microsoft.com/kb/310316) that addresses the issue. The bottom line is that I set the registry entry mentioned in that article for each user that creates the file. This may not be an acceptable solution in your case but it works for me.

                  V Offline
                  V Offline
                  vivekphlp
                  wrote on last edited by
                  #8

                  skornel . .. MY actual requirement is - i have a file, that is having "R" only permision for users... its some thing like a log file. THe program has to be RUN in USER MODE(Restricted permission). But in betweeen i have to switch to admin mode to make some chnges in that file. Iam trying to use cacl - a windows command to change file permission

                  Proud To Be an Indian

                  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