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 create a file shared among all users

how to create a file shared among all users

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 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.
  • J Offline
    J Offline
    Joseph Marzbani
    wrote on last edited by
    #1

    I used the following code to create a file, so that every user can read, modify, delete and write to it:

    CreateFile(
    m_szLogFilePath,
    GENERIC_WRITE,
    FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
    NULL,
    OPEN_ALWAYS,
    FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
    NULL);

    but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?

    Thank you masters!

    CPalliniC D 2 Replies Last reply
    0
    • J Joseph Marzbani

      I used the following code to create a file, so that every user can read, modify, delete and write to it:

      CreateFile(
      m_szLogFilePath,
      GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
      NULL,
      OPEN_ALWAYS,
      FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
      NULL);

      but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?

      Thank you masters!

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      I guess your proble is related with the NULL value of the fourth parameter, see [^]. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      In testa che avete, signor di Ceprano?

      J 1 Reply Last reply
      0
      • CPalliniC CPallini

        I guess your proble is related with the NULL value of the fourth parameter, see [^]. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        J Offline
        J Offline
        Joseph Marzbani
        wrote on last edited by
        #3

        :confused: so what?

        Thank you masters!

        CPalliniC 1 Reply Last reply
        0
        • J Joseph Marzbani

          :confused: so what?

          Thank you masters!

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #4

          Provided my guess is correct (I'm not an expert about) you've to explicitely create a security descriptor, see [^]. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          In testa che avete, signor di Ceprano?

          O 1 Reply Last reply
          0
          • J Joseph Marzbani

            I used the following code to create a file, so that every user can read, modify, delete and write to it:

            CreateFile(
            m_szLogFilePath,
            GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
            NULL,
            OPEN_ALWAYS,
            FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN,
            NULL);

            but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?

            Thank you masters!

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

            Jusef Marzbany wrote:

            but when I log in with a user other than one in which I created the file, I can not save any modification in it neither delete it. any help?

            What error message are you receiving?

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            1 Reply Last reply
            0
            • CPalliniC CPallini

              Provided my guess is correct (I'm not an expert about) you've to explicitely create a security descriptor, see [^]. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              O Offline
              O Offline
              Omri121
              wrote on last edited by
              #6

              You are probably right. If you want to have EVERYONE permission, you need to create new security descriptor. NULL says that the default ACL is used, i.e. only the user or someone with higher privileges (administrator for example) can change the file. Try this: SECURITY_ATTRIBUTES m_pSecAttrib; SECURITY_DESCRIPTOR* m_pSecDesc; m_pSecDesc = (SECURITY_DESCRIPTOR*)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH); InitializeSecurityDescriptor(m_pSecDesc, SECURITY_DESCRIPTOR_REVISION); SetSecurityDescriptorDacl(m_pSecDesc,TRUE,(PACL)NULL,FALSE)) m_pSecAttrib.nLength = sizeof(SECURITY_ATTRIBUTES); m_pSecAttrib.bInheritHandle = TRUE; m_pSecAttrib.lpSecurityDescriptor = m_pSecDesc; It should create security descriptor with EVERYONE permission. Instead of NULL, send &m_pSecAttrib. Hope I helped.

              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