tags:

views:

101

answers:

4

Hi, I'm new here, so I don't have the time to contribute before I ask for u guys' help, so pardon me for that.

I'm not sure if this can be done, but I would like to find out the opened file(s) of an application.

Here I don't mean the "internal" opened files, but are those that are opened by the end-user (either by invoking the handling app thru file-assoc, or explicitely inside the app). Think *.cs or *.vb files in Visual Studio (yeah I'm an MS guy) or text files in Notepad.

I've looked at "verbs" in the Win Shell MSDN doc, but it only mentions the invoking, and no way to inspect info of invoked verbs. I also looked at DDE, but it looks like a general purpose facility and does not fit into my case here.

I have to say that my situation is difficult to be solved by Googling because of the lack of unique key words, so this would definitely needs human attention :)

Thanks

+2  A: 

If you want to inspect a running process for open handles, you can use ProcessExplorer or the command-line application Handle.

ProcessExplorer is essentially the Windows Task Monitor on steroids. It's a very useful tool in day-to-day computing, as well as process debugging. I highly recommend it.

Ben S
I think the challenge here is that he wants only the files opened by the user using the software not any application initiated file opens, i.e. .docx not dll, temp files, etc.
Lazarus
You can filter for those requirements in Process Explorer.
Ben S
A: 

There is a utility found in SysInternals which can list the files opened by an application Link here

tommieb75
PsFile would be the one you are looking for
tommieb75
Thanks, but I would like to do so programmatically, so this might not be the right tool to me
im_chc
A: 

A quick one that only works for file-locking is a shell extension called WhoLockMe. It's not as powerful as some of the other tools here, but it's a context menu away in Windows explorer.

Broam
A: 

Hi -

I assume that you are a C# programmer, and want some code to do this. As far as I know, there is no easy programming API to find out this information - it isn't the Win32 API, but rather the Windows internal API. However, the SysInternals suite of command line utilities (http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx) can be used to find out this information.

The application you want is called Handle.

There will be no differences to the OS between what you call "internal files" (presumably ones opened by the program without user involvement) and ones which the user deliberately used. You will have to supply this information by specifying the extension of the file. For instance, if you wanted to find all the word files open in Word, the command line you would need is:

handle -p winword.exe | find ".doc"

If writing an app in C#, you could use the following class to return a list of open documents which match your pattern (note this contains a form called ShowOpenAppFilesForm, with two text boxes appExeNameTextBox and fileExtensionTextBox, and a list box openFileListBox):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;

namespace ShowOpenAppFiles
{
 public partial class ShowOpenAppFilesForm : Form
 {
  private const string HandlePath = @"D:\Development\SysInternals\SysinternalsSuite\Handle.exe";

  public ShowOpenAppFilesForm()
  {
   InitializeComponent();
  }


  private void showButton_Click(object sender, EventArgs e)
  {
   string[] fileExtensions = new string[1];
   fileExtensions[0] = fileExtensionTextBox.Text;
   openFileListBox.DataSource = Show(appExeNameTextBox.Text, fileExtensions);
  }

  private List<string> Show(string programExeName, string[] fileExtensions)
  {
   Process childProcess = new Process();
   ProcessStartInfo startInfo = childProcess.StartInfo;
   startInfo.FileName = HandlePath;
   startInfo.Arguments = " -p " + programExeName;
   startInfo.CreateNoWindow =false;
   startInfo.ErrorDialog = false;
   startInfo.RedirectStandardOutput = true;
   startInfo.UseShellExecute = false;

   childProcess.Start();

   StreamReader stdOutput = childProcess.StandardOutput;

   List<string> fileNameList = new List<string>();

   while (!stdOutput.EndOfStream)
   {
    string line = stdOutput.ReadLine();
    for (int i = 0; i < fileExtensions.Length; i++)
    {
     if (line.Contains("." + fileExtensions[i]))
     {
      fileNameList.Add(line.Substring(21));
     }
    }
   }
   childProcess.WaitForExit();

   return fileNameList;
  }
 }
}

[Incidentally, DDE is mostly toast now.]

Mark Bertenshaw