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. Handle Inheritance in Windows [modified]

Handle Inheritance in Windows [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
securityoophelptutorial
9 Posts 5 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
    Sudhan Gandhi
    wrote on last edited by
    #1

    Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!

    modified on Monday, March 21, 2011 7:13 AM

    _ M E 3 Replies Last reply
    0
    • S Sudhan Gandhi

      Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!

      modified on Monday, March 21, 2011 7:13 AM

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Look at the documentation for SetHandleInformation and DuplicateHandle.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      S 1 Reply Last reply
      0
      • _ _Superman_

        Look at the documentation for SetHandleInformation and DuplicateHandle.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        S Offline
        S Offline
        Sudhan Gandhi
        wrote on last edited by
        #3

        Hi, I know how it is passed. I want to know how to retrieve and use them in child process. An example will help Sudhan

        L 1 Reply Last reply
        0
        • S Sudhan Gandhi

          Hi, I know how it is passed. I want to know how to retrieve and use them in child process. An example will help Sudhan

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          A simple MSDN search yielded this[^].

          I must get a clever new signature for 2011.

          S 1 Reply Last reply
          0
          • L Lost User

            A simple MSDN search yielded this[^].

            I must get a clever new signature for 2011.

            S Offline
            S Offline
            Sudhan Gandhi
            wrote on last edited by
            #5

            I had seen this link. I was wondering how to use it for other type of handles (like mutex, sempahore etc, though they can be retrieved through api like OpenMutex) in child process.

            L 1 Reply Last reply
            0
            • S Sudhan Gandhi

              I had seen this link. I was wondering how to use it for other type of handles (like mutex, sempahore etc, though they can be retrieved through api like OpenMutex) in child process.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              This issue is specifically about File Handles as far as I know; the other types do not fall into the same category.

              I must get a clever new signature for 2011.

              1 Reply Last reply
              0
              • S Sudhan Gandhi

                Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!

                modified on Monday, March 21, 2011 7:13 AM

                M Offline
                M Offline
                Michael Dunn
                wrote on last edited by
                #7

                You described how to make the handle available in the child process, but you still need to tell the child the numerical value of the HANDLE. A common way of doing this is to pass the value as a command line parameter.

                --Mike-- Dunder-Mifflin, this is Pam.

                S 1 Reply Last reply
                0
                • S Sudhan Gandhi

                  Hi, I am looking for code sample which will explain how to actually pass handles from parent to child process. I konw: A child process can inherit handles from its parent process. An inherited handle is valid only in the context of the child process. To enable a child process to inherit open handles from its parent process, use the following steps. 1.Create the handle with the bInheritHandle member of the SECURITY_ATTRIBUTES structure set to TRUE. 2.Create the child process using the CreateProcess function, with the bInheritHandles parameter set to TRUE. Can someone please share some code sample which would help me understand how to actually use the passed handle in child process. Thanks in advance!!!

                  modified on Monday, March 21, 2011 7:13 AM

                  E Offline
                  E Offline
                  Emilio Garavaglia
                  wrote on last edited by
                  #8

                  When you create an object (like a mutex) you can specify a "name". (see CreateMutex[^]). In the child process you can retrieve another handle to that same object with OpenMutex[^], or whatever similar and coherent with the type of object) by giving it that name (that is supposed to be unique at least between all your entangled processes). Note that the returned value may be different, due to the fact the the handle value is an "index of a table of indexes" that is different in the various processes. The documentation talks improperly of inheritance of handles. What are inherited are the objects the handle refers to.

                  2 bugs found. > recompile ... 65534 bugs found. :doh:

                  1 Reply Last reply
                  0
                  • M Michael Dunn

                    You described how to make the handle available in the child process, but you still need to tell the child the numerical value of the HANDLE. A common way of doing this is to pass the value as a command line parameter.

                    --Mike-- Dunder-Mifflin, this is Pam.

                    S Offline
                    S Offline
                    Sudhan Gandhi
                    wrote on last edited by
                    #9

                    Hi Mike, This is what I was looking for. Handles are copied in the process table of the child process if the inherit flag is set to true but how would the child process know which handle is pointing to which kernel object and which to use. This link [^] explains the concept: "To use a handle, the child process must retrieve the handle value and "know" the object to which it refers. Usually, the parent process communicates this information to the child process through its command line, environment block, or some form of interprocess communication." I was looking for an sample code showing the above step(highlighted in bold).

                    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