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. Which process opened a file?

Which process opened a file?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 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.
  • D Offline
    D Offline
    daavena
    wrote on last edited by
    #1

    Hi all, could you give me a little hint how to get a name of process which opened file? example: I have a file C:\temp\test.txt - I need to know which process opened this file. Thanks.

    L S H 3 Replies Last reply
    0
    • D daavena

      Hi all, could you give me a little hint how to get a name of process which opened file? example: I have a file C:\temp\test.txt - I need to know which process opened this file. Thanks.

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

      You can use NtQuerySystemInformation() and pass 'SystemHandleInformation' as the SYSTEM_INFORMATION_CLASS. You will need to iterate through the returned buffer and locate the handle and match it with the process ID. http://msdn2.microsoft.com/en-us/library/ms724509.aspx[^] http://www.codeguru.com/Cpp/W-P/system/processesmodules/article.php/c2827[^] Best Wishes, -David Delaune

      1 Reply Last reply
      0
      • D daavena

        Hi all, could you give me a little hint how to get a name of process which opened file? example: I have a file C:\temp\test.txt - I need to know which process opened this file. Thanks.

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Do you want a utility to do this or know how to code it yourself? SysInternals have utilities that can tell you this information.

        Steve

        1 Reply Last reply
        0
        • D daavena

          Hi all, could you give me a little hint how to get a name of process which opened file? example: I have a file C:\temp\test.txt - I need to know which process opened this file. Thanks.

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Did you need to this code?

          DWORD m_Return=GetModuleFileNameEx(hProcess, hModuleHandle, str1, sizeof(str1) );

          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