Hi there.
I have a C# console application that extracts data to flat files. Some
of my business partners begin consuming these extract files before I've
had a chance to write the newest ones (I am extracting these files once
a day beginning at midnight). Since one or more consumer has a
particular extract file open, I need to detect this and then take
action to close all open file connections so I can put the new extract
file out onto the network share where the extracts reside.
I've managed to use the psfiles.exe (from sysinternals.com) and write a
C# class that runs the psfiles.exe in a separate process, captures the
standard out (or standard error) and then parses this output into a
custom OpenFile object containing the process ID and user that has the
file open.
This seems to work okay. It seems like a rather large hack, though.
This method also suffers from a limitation. From what I can tell (and
I've tried several ways) I cannot get info about files opened on the
system where I'm running my console application from - much less close
the connections to any local files.
I've started looking into calling the Win32 API calls (i.e.
NetFileEnum, NetFileClose and others) using DLLImport from C# but I'm
afraid I have no C/C++ coding skills to speak of.
Does anyone know of another small utility/.exe that gets both remote
and local open file connection information, and allows the closing of
the open file connections? If not, is there some type of beginner's
tutorial that I can read that can get me started with C# Win32 API
coding?
Thougths? I appreciate any help.
Thanks in advance,
/bc