?
Solved

How to determine what process has file locked

Posted on 2005-03-22
1
Medium Priority
?
542 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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