Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

openfiles /disconnect

1,257 views
Skip to first unread message

Mr Simon

unread,
Oct 1, 2013, 6:37:16 AM10/1/13
to
Hi all,

Can anyone help with the below - I've spent 6 hours on it (to my
embarrasment), including variations using psfile, and it's driving me mad
:-\

We have a bespoke app which sometimes leaves files open on the server
causing problems at our end of day. This batch file closes the files, and
works fine on 2003 server. On a couple of SBS 2011 servers though it DOESN'T
work :-\ Not sure if this is a change of syntax thing, something to do with
elevation etc :-(

openfiles /query /v | find "\CUJO\" > "%temp%\openfiles.txt"
for /f "eol=; tokens=2 delims= " %%i in (%temp%\openfiles.txt) do (
openfiles /disconnect /id %%i
)

Basically it lists open files on the system which have "\CUJO\" in the path
(The name of the bespoke app).. Dumps the info out to a file, then reads in
the file handles and attempts to close them.

Has worked for YEARS on 2003.. Now all I get is a new line, no error
message, but when listing the open files again everything is still there :-(

Can anyone help!?!

Simon.


foxidrive

unread,
Oct 1, 2013, 6:53:44 AM10/1/13
to
On 1/10/2013 20:37, Mr Simon wrote:

> We have a bespoke app which sometimes leaves files open on the server
> causing problems at our end of day. This batch file closes the files, and
> works fine on 2003 server. On a couple of SBS 2011 servers though it DOESN'T
> work :-\ Not sure if this is a change of syntax thing, something to do with
> elevation etc :-(
>
> openfiles /query /v | find "\CUJO\" > "%temp%\openfiles.txt"
> for /f "eol=; tokens=2 delims= " %%i in (%temp%\openfiles.txt) do (
> openfiles /disconnect /id %%i
> )
>
> Basically it lists open files on the system which have "\CUJO\" in the path
> (The name of the bespoke app).. Dumps the info out to a file, then reads in
> the file handles and attempts to close them.
>
> Has worked for YEARS on 2003.. Now all I get is a new line, no error
> message, but when listing the open files again everything is still there :-(
>

Without a 2011 server to test on or without seeing a sample of the "%temp%\openfiles.txt" file then we'd
really be guessing .

I do suspect there may be some long filename/path characters so perhaps enclosing the very last %%i in
quotes, ala "%%i" may help.

If that doesn't help, then type the openfiles command manually with one of the file entries, and see what
you can see on the console - like this or whatever format it takes:

openfiles /disconnect /id \cujo\runme.exe


foxi

Mr Simon

unread,
Oct 1, 2013, 7:03:16 AM10/1/13
to
Hi Foxidrive, thanks for the reply :-)

> Without a 2011 server to test on or without seeing a sample of the "%temp%
> \openfiles.txt" file then we'd really be guessing .

To keep post tidy, one line of the file is:

SVR-WAREHOU-DC1 38252052 RYAN.SCOTT Windows 0 Write + Read
C:\Shares\Company\CUJO\NETINFO\DATA\LOGIN.CDX

Basically it's format is:

Hostname FileID Username ? ? Mode Filespec

(Not 100% sure what cols 4/5 are; 4 always says Windows, 5 is 0 or 1)

> I do suspect there may be some long filename/path characters so perhaps
> enclosing
> the very last %%i in quotes, ala "%%i" may help.

The FileID is just an 8 digit number :-(

> If that doesn't help, then type the openfiles command manually with one of
> the file entries,
> and see what you can see on the console - like this or whatever format it
> takes:
> openfiles /disconnect /id \cujo\runme.exe

c:\> openfiles /disconnect /id 88888888

c:\>

That's it - no result back :-\

And no errorlevel :-(


foxidrive

unread,
Oct 1, 2013, 8:53:03 AM10/1/13
to
Right click and elevate to admin console - then type in the command. Maybe it's a permissions issue.

foxidrive

unread,
Oct 1, 2013, 8:55:26 AM10/1/13
to
On 1/10/2013 22:53, foxidrive wrote:
> On 1/10/2013 21:03, Mr Simon wrote:

>> To keep post tidy, one line of the file is:
>>
>> SVR-WAREHOU-DC1 38252052 RYAN.SCOTT Windows 0 Write + Read
>> C:\Shares\Company\CUJO\NETINFO\DATA\LOGIN.CDX
>>
>> Basically it's format is:
>>
>> Hostname FileID Username ? ? Mode Filespec
>>
>> (Not 100% sure what cols 4/5 are; 4 always says Windows, 5 is 0 or 1)
>>
>> c:\> openfiles /disconnect /id 88888888
>>
>> c:\>
>>
>> That's it - no result back :-\
>>
>> And no errorlevel :-(
>
> Right click and elevate to admin console - then type in the command. Maybe it's a permissions issue.

I noticed you typed in 88888888 and it really should be a valid file ID so you can then check if the file
was disconnected.


Mr Simon

unread,
Oct 1, 2013, 9:17:50 AM10/1/13
to
"foxidrive" <foxi...@server.invalid> wrote:
>>
>> c:\>
>>
>> That's it - no result back :-\
>>
>> And no errorlevel :-(
>
> Right click and elevate to admin console - then type in the command.
> Maybe it's a permissions issue.

Tried, confirmed as "elevated", with "Administrator: Command Prompt" in the
window :-(

Driving me mad!! :-D


Mr Simon

unread,
Oct 1, 2013, 9:19:27 AM10/1/13
to
"foxidrive" <foxi...@server.invalid> wrote:
>
> I noticed you typed in 88888888 and it really should be a valid file ID so
> you
> can then check if the file was disconnected.

Yep, that was just for illustration rather than re-typing a valid one here.

For confirmation, the command:

c:\> openfiles /disconnect /id 88888888

Just returns straight to a prompt, no message or errorlevel, regardless of
whether the fileid is valid or not :-(


Herbert Kleebauer

unread,
Oct 1, 2013, 11:44:21 AM10/1/13
to
On 01.10.2013 15:19, Mr Simon wrote:

> c:\> openfiles /disconnect /id 88888888
>
> Just returns straight to a prompt, no message or errorlevel, regardless of
> whether the fileid is valid or not :-(

Is there a batch file "openfiles.bat" in the current directory?




Mr Simon

unread,
Oct 1, 2013, 1:18:52 PM10/1/13
to
"Herbert Kleebauer" <kl...@unibwm.de> wrote in message
news:l2eqor$82o$1...@speranza.aioe.org...
There's not!

To confirm I'm running the right "openfiles" too, I can "openfiles /?"
successfully :-(



JJ

unread,
Oct 1, 2013, 10:43:55 PM10/1/13
to
On Tue, 1 Oct 2013 11:37:16 +0100, Mr Simon wrote:
> This batch file closes the files, and
> works fine on 2003 server. On a couple of SBS 2011 servers though it DOESN'T
> work :-\ Not sure if this is a change of syntax thing, something to do with
> elevation etc :-(

If it's only a couple of more SBS 2011 servers, it means that those servers
are not exactly identical. The batch file do work on some SBS 2011 servers,
so it's not the cause of problem.

> Has worked for YEARS on 2003.. Now all I get is a new line, no error
> message, but when listing the open files again everything is still there :-(
[paste]
> c:\> openfiles /disconnect /id 88888888
>
> c:\>
>
> That's it - no result back :-\
>
> And no errorlevel :-(
[paste]
> For confirmation, the command:
>
> c:\> openfiles /disconnect /id 88888888
>
> Just returns straight to a prompt, no message or errorlevel, regardless of
> whether the fileid is valid or not :-(
[paste]
> To confirm I'm running the right "openfiles" too, I can "openfiles /?"
> successfully :-(

I'm pointing my finger at the openfiles.exe or the system where
openfiles.exe doesn't work. The cause be one or both of these:

* Old (buggy) openfiles.exe version. There may be a hotfix that update that
file, and that couple of SBS servers whose openfiles.exe isn't working, may
not have that hotfix yet. Or... it's the other way around as mentioned on
the next point.

* Faulty hotfixes. Hotfixes have been proven that they're not always fix
things. They can broke part of the system or cripple entire system. This may
be related to the hotfix for Windows 8 lines:

http://support.microsoft.com/kb/2867224

Microsoft may have unofficially released a hotfix for SBS 2011, but is not
publicized yet. Some of you SBS systems may have picked it up via Windows
Update.

* Malware infection. While most of the effects are cripple entire program,
it may coincidentally nullifies part of a program.

I suggest you scan your system for malwares, just to be safe.

Then test using openfiles.exe from the SBS DVD. Copy it along with any
openfiles.exe.mui to a temporary folder. Use 7-Zip (or built-in Windows
tool?) to open the WIM file in the DVD and extract the file.

You may want to compare the openfiles.exe file's version from the system
that work, and that doesn't. To see if it's a hotfix issue.

Or as a workaround, you can use net.exe to close the files using their ID
(and use openfiles.exe to list them). e.g:

net file 88888888 /close

Mr Simon

unread,
Oct 2, 2013, 7:23:33 AM10/2/13
to
"JJ" <d...@nah.meh> wrote:
>>
>> This batch file closes the files, and
>> works fine on 2003 server. On a couple of SBS 2011 servers though it
>> DOESN'T
>> work :-\ Not sure if this is a change of syntax thing, something to do
>> with
>> elevation etc :-(
>
> If it's only a couple of more SBS 2011 servers, it means that those
> servers
> are not exactly identical. The batch file do work on some SBS 2011
> servers,
> so it's not the cause of problem.

Hi JJ, thanks for the reply :-)

My original post may not have been clear. It's not a couple out of many SBS
2011's it doesn't work on.. We have a mix of 2003/2011 servers, and it's
just the 2011 ones that the script doesn't work on, if you see what I mean
:-)

> Or as a workaround, you can use net.exe to close the files using their ID
> (and use openfiles.exe to list them). e.g:
>
> net file 88888888 /close

"net file" was one of the alternatives I looked at in my 6+ hours of trying
to get this bugger working. Unfortunately openfiles returns fileid's that
are 2 characters too short to pass to "net file".

I can't even switch to using "net files" entirely, as the list of open files
it returns is truncated with "....."'s rather than the full path! So I
couldn't to the find "\CUJO\" part reliably. Example:

1811939920 C:\Shares\...\PAYDATA\PAYROLL.ldb JUDE.LAKE
3959423570 C:\Users\...\Start Menu CUSTOMER.SERVICES

If there was a switch for "net files" to show the full path I'd be laughing,
as "net files id /close" when entered DOES work!! :-(


Mr Simon

unread,
Oct 2, 2013, 7:34:49 AM10/2/13
to
"JJ" <d...@nah.meh> wrote:


Hi JJ,

Mentioning "net files" again made me look again at the fileid's.

Where I've been using "openfiles /query /v" which returns output like this:

SERVERNAME 88888888 USERNAME...
SERVERNAME 99999999 USERNAME... etc..

These fileid's are 2 numbers too short for net files because if I do "net
files" I get this:

8888888800 MANGLEDFILEPATH USERNAME...
9999999900 MANGLEDFILEPATH USERNAME.. etc..

Now although that second method gets me the full fileid, it's unusable as I
can't guarantee it'd find every instance of "\CUJO\" in the mangled path it
returns. However I've just realised I can do "openfiles /query /fo csv"
which gets me:

"8888888800","USERNAME","UNALTEREDFILEPATH"
"9999999900","USERNAME","UNALTEREDFILEPATH"

So I guess my original file needs changing to something like the following
pseudo-code (I've yet to work out how to do it!!)

openfiles /query /fo csv | find "\CUJO\" > "%temp%\openfiles.txt"
for each line in (%temp%\openfiles.txt), take the first csv column value
and..
net files %%i /close
)

(Off to Google parsing CSV with batch files!!)


foxidrive

unread,
Oct 2, 2013, 7:52:38 AM10/2/13
to
Based on that, this should work:

@echo off
for /f "delims=," %%a in (' openfiles /query /fo csv ^| find /i "\CUJO\" ') do net files %%~a /close



foxi

Mr Simon

unread,
Oct 2, 2013, 11:43:46 AM10/2/13
to
"foxidrive" <foxi...@server.invalid> wrote:
>
> Based on that, this should work:
>
> @echo off
> for.....
>
> foxi

Hahaha, first class! Worked a treat - many thanks!! :-D

Separated it off onto two lines, only because further on in the batch file I
email the "openfiles.txt" somewhere, so it's handy having it lying around in
%temp%

When it's on one line is purpose of the ^ just to escape the | when the
command is in ''s?

No idea why openfiles doesn't work as it has in the past like on 2003, but
this is a perfect workaround :-)


foxidrive

unread,
Oct 2, 2013, 7:27:10 PM10/2/13
to
On 3/10/2013 01:43, Mr Simon wrote:
>
> Hahaha, first class! Worked a treat - many thanks!! :-D

Bewdy.

> Separated it off onto two lines, only because further on in the batch file I
> email the "openfiles.txt" somewhere, so it's handy having it lying around in
> %temp%
>
> When it's on one line is purpose of the ^ just to escape the | when the
> command is in ''s?

Yes.

0 new messages