4

I was doing a PowerShell script for a quicker way of closing locked files on a big Windows Server 2008 R2 file server (more than 2500 files opened at this moment, and the peak hour was like 3-4 hours ago), and I'd to choose between net files or openfiles. So I went with openfiles as is newer and it can give the full path of the file (net files can do that too, but you've to query every single ID).

I was having problems with it: some files won't close. I checked with net files, and all was ok... So I've started to take a closer look, and this is (an excerpt of) what I've found:

C:\> net files

ID         Path                                    User name            # Locks

-------------------------------------------------------------------------------
3221368833 G:\Users\...                            SomeUser              3
2550215683 G:\Users\...                            SomeUser              3
3422797829 G:\Users\...                            SomeUser              0
805310474  F:\Recursos\...                         SomeUser              3
335585292  G:\Users\SomeUser\My Documents          SomeUser              0
4026636306 G:\Users\SomeUser\Desktop               SomeUser              0
2684396568 G:\Users\...                            SomeUser              0
2952839192 G:\Users\...\EXCEL\SomeFolder2016       SomeUser              0
4160993304 G:\Users\...                            SomeUser              0
1610613364 F:\Recursos\Suministros                 SomeUser              0
The command completed successfully.

C:\> openfiles /query /v

Files opened remotely via local share points:
---------------------------------------------

Hostname        ID       Accessed By          Type       #Locks     Open Mode       Open File (Path\executable)

=============== ======== ==================== ========== ========== =============== ============================================================================
MyServer        32213688 SomeUser             Windows    3          Write + Read    G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer        25502156 SomeUser             Windows    3          Write + Read    G:\Users\SomeUser\My Documents\[SomePath].xls
MyServer        34227978 SomeUser             Windows    0          Write + Read    G:\Users\SomeUser\My Documents\[SomePath].xls
MyServer        80531047 SomeUser             Windows    3          Write + Read    F:\Recursos\Suministros\[SomePath].xls
MyServer        33558529 SomeUser             Windows    0          Read            G:\Users\SomeUser\My Documents
MyServer        40266363 SomeUser             Windows    0          Read            G:\Users\SomeUser\Desktop
MyServer        26843965 SomeUser             Windows    0          Write + Read    G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer        29528391 SomeUser             Windows    0          Read            G:\Users\SomeUser\My Documents\EXCEL\SomeFolder2016
MyServer        41609933 SomeUser             Windows    0          Write + Read    G:\Users\SomeUser\My Documents\[SomePath].XLS
MyServer        16106133 SomeUser             Windows    0          Read            F:\Recursos\Suministros

Wait, the IDs are different... Hell, no, the openfiles IDs are truncated!!

So obviously for the script itself, I'm for the moment going for net files, get the IDs, query each single ID so I get the full path, and from there I can reuse the rest of the script.

But for the sake of my sanity: is this a bug? A feature? Windows Server 2008 R2 is not new, and I was not able to find any reference to this, not to talk about a hotfix!

curropar
  • 631
  • 3
  • 18
  • Why are you doing this in the first place? – joeqwerty Feb 15 '16 at 17:37
  • To quickly find files by a part of their name (users are in fact not providing the full name), so something like: MyScript PartialName will give me all files with that string on their fullpath, then I select the one I want to close. – curropar Feb 15 '16 at 17:41
  • I meant why are you closing the files? Users have them open and are using them, no? – joeqwerty Feb 15 '16 at 17:42
  • Ah, yes, sorry! The problem is users forget to close the files, they leave, then colleagues from other shift come in, and they cannot edit them. – curropar Feb 15 '16 at 17:45
  • Oh, gotcha. Now I understand. – joeqwerty Feb 15 '16 at 17:46

1 Answers1

4

So three years later, I've found an answer and a solution, or workaround: this is a bug of the default output of openfiles, which is table. If you specify the options /FO CSV or /FO List, IDs are complete.

curropar
  • 631
  • 3
  • 18