Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to determine what process has file locked

Posted on 2005-03-22
1
Medium Priority
?
549 Views
Last Modified: 2012-08-14
I have an application that writes files out, and I am getting System.IO.IOException because it is in use by another process. How can I determine what process is using this file?  (a PID would be great).

Here's the current code
         try
            Dim sr As StreamWriter = File.CreateText(_strFileName)
            sr.WriteLine(FileContents)
            sr.Close()
        catch e as Exception
                 '..handle
        end try
0
Comment
Question by:lrr81765
1 Comment
 
LVL 12

Accepted Solution

by:
fruhj earned 1500 total points
ID: 13603327
Do you need to do this in code or just need to figure it out once so you can shut down the other app?

If you just need to see it once, there's a few excellent utilities over at sysinternals

http://www.sysinternals.com/ntw2k/freeware/procexp.shtml (Gui utility for showing what files are opened by what pids)
or
http://www.sysinternals.com/ntw2k/freeware/handle.shtml  (Command line util to show what files are opened by what pids)

(you might also find filemon.exe and regmon.exe useful - they tell you in real time what files/registry keys are being accessed on your system)

if you need to do it in your own code, they've written a book under Microsoft press called Windows Internals, 4th edition: http://www.sysinternals.com/windowsinternals.shtml

- Jack
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question