views:

180

answers:

3

opening a file in WINDOWS/system32/LogFiles with

    using (StreamReader r = new StreamReader(fileName))

generates exception "because the file is in use by another process". How can I figure out what the other process is? Could it be the server updating the logs? If it is, how can I ensure that my associated scheduled task can also have access?

thanks!

I'm afraid I don't have the auth to install programs on this server.

+2  A: 

This is disturbingly old school, but I love this really bad utility called: wholockme http://www.dr-hoiby.com/WhoLockMe/

It lets you know who has files locked.

Jacob

TheJacobTaylor
+1  A: 

Personally, I prefer ProcessExplorer with its "Find Handle" functionality.

You could also try opening a file in a shared mode:

using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (StreamReader r = new StreamReader(fs))
    ...
VladV
A: 

If you want to find out who has the file open, my favorite app for this is Handle by SysInternals (http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx). I know you said you don't have authority to install apps, this is just a single executable that you run, and you could run it from a network share if you wanted.

I've had the LogFiles lock problem with SMTP service logs, my solution was just to copy the file to another location and open it from there. Might work for what you're doing.

Brad