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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. To know which file was opened by an application.

To know which file was opened by an application.

Scheduled Pinned Locked Moved C#
tutorial
4 Posts 3 Posters 2 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.
  • Y Offline
    Y Offline
    yjoo9317
    wrote on last edited by
    #1

    Hi, For example, I am trying to know when I opened, say,'example.doc' word file or 'example.pdf' file. I know msword or acrobat is running... But how can we know which file was opened by msword or acrobat. FileSytemWatcher looks like responding on only the events which changed file content. Reading a file isn't an event reported by the watcher. Process gave me module name but not the target file(doc or pdf file name). Maybe I am missing some user32 functions. But at this point, I don't know how to retrieve that information. Many thanks in adance, yjoo.

    M 1 Reply Last reply
    0
    • Y yjoo9317

      Hi, For example, I am trying to know when I opened, say,'example.doc' word file or 'example.pdf' file. I know msword or acrobat is running... But how can we know which file was opened by msword or acrobat. FileSytemWatcher looks like responding on only the events which changed file content. Reading a file isn't an event reported by the watcher. Process gave me module name but not the target file(doc or pdf file name). Maybe I am missing some user32 functions. But at this point, I don't know how to retrieve that information. Many thanks in adance, yjoo.

      M Offline
      M Offline
      malharone
      wrote on last edited by
      #2

      FileSytemWatcher is watching for changes. When you open a file, the OS puts a virtual lock on the file but does actually modify the file. But when a file is saved, the FSW will trigger the modify event. - Malhar

      Y 1 Reply Last reply
      0
      • M malharone

        FileSytemWatcher is watching for changes. When you open a file, the OS puts a virtual lock on the file but does actually modify the file. But when a file is saved, the FSW will trigger the modify event. - Malhar

        Y Offline
        Y Offline
        yjoo9317
        wrote on last edited by
        #3

        Thanks for reply... Yes,I know we can detect any changes if made to a file. In case of pdf file, The file will unlikely change. What I want is that, if I know msword or acrobat(these are examples) is running, then I want to know which file was opened by the application. Thanks..

        D 1 Reply Last reply
        0
        • Y yjoo9317

          Thanks for reply... Yes,I know we can detect any changes if made to a file. In case of pdf file, The file will unlikely change. What I want is that, if I know msword or acrobat(these are examples) is running, then I want to know which file was opened by the application. Thanks..

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          There is no easy little API call to make. This will require a black belt in Windows internals. Not all expose an API to tell you what files that app has open, and most apps don't expose any kind of API at all. You'd have to enumerate the handles of the process you're interested in, be it Word or Acrobat Reader. The problem is this technique is not documented anywhere, source code for it is very sparse, and it's all written in C++. You can find an example buried in the source for a Task Manager Extension, found right here[^] on CodeProject. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          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