I work on a application where i want to find out which files on my filesystem is used by a Process.
After trying around with the System.Diagnostics.Process class, and didn´t get the resulst i wanted i find the application called OpenedFileView from Nirsoft.
http://www.nirsoft.net/utils/opened_files_view.html
Basically it does exactly what i want but i have some problems with the implimication in my project.
The option wich “OpenedFileView” gives you is to start it with some arguments that it creates you an txt file with all the information i want.
But for my case i want to whach the processes in realtime, and if i start the application repetitively i always have the hourglass at my mouse cursor.
So after this i tryed some ways to get rid of it, tryed out to put it in a BackgroundWorker Thread. But this changed nothing at all. I also looked for a way to force the Process not to exit, and sending new arguments to it, but this also didn´t worked.
So is there any way to use this application in the way I want, or does this didn´t work at all?
I hope somebody can help me either with getting away this annoying mouse cursor hourglass, or with a better implimication of this application so i can use it in realtime!
Thanks alot!
private void start()
{
_openedFileView = new Process();
_openedFileView.StartInfo.FileName = "pathToApp\\OpenedFilesView.exe";
_openedFileView.EnableRaisingEvents = true;
_openedFileView.Exited += new EventHandler(myProcess_Exited);
_openedFileView.StartInfo.Arguments = "/scomma pathToOutputFile";
_openedFileView.Start();
}
private void myProcess_Exited(object sender, System.EventArgs e)
{
start();
}
You’ll have to tweak your “real-time” requirement. A process can open and close hundreds of files in the time it takes to start that program. Given that you can never get a truly accurate view of file usage, you might as well reduce the rate at which you start the program. One immediate benefit is that you’ll greatly reduce the CPU load.
A better mousetrap is the Sysinternals’ Handle utility. It’s a much lighter weight program. And is a console mode app, you can redirect its output so you don’t have to use a file. And there’s no wait cursor. It also allows selecting a specific process with the -p command line argument, an option you really want to use to keep execution time down to a reasonable level. This sample code worked pretty well:
Oh, and resist the temptation to use its “close file” option. That’s only good if you are looking for a way to permanently destroy data on your hard drive.