<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How to close open files on a server share</title>
	<atom:link href="http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/feed/" rel="self" type="application/rss+xml" />
	<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/</link>
	<description>/*** Code's last stand ***/</description>
	<lastBuildDate>Mon, 24 Oct 2011 08:14:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Chris</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-359</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 24 Oct 2011 08:14:51 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-359</guid>
		<description>Thanks a lot for this Script, I was looking exactly for this and it does its job perfectly.</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this Script, I was looking exactly for this and it does its job perfectly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashley</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-349</link>
		<dc:creator>Ashley</dc:creator>
		<pubDate>Mon, 25 Oct 2010 22:01:35 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-349</guid>
		<description>I managed to get what I wanted by the below code.  It closes all open files in the path specified on the server when run.  Hope this helps?


Dim Share 

Set objConnection = GetObject(&quot;WinNT://SERVERNAME/LanmanServer&quot;)
Set colSessions = objConnection.Sessions
Set colResources = objConnection.Resources
Set Shell = CreateObject(&quot;WScript.Shell&quot;)

On Error Resume Next

For Each objResource in colResources
	
	Share = left(objResource.Path,53)
	If Share = &quot;F:\Infrastructure\Snowinst2\AppData\Nielsen\database\&quot; Then

		Shell.Run&quot;OPENFILES /Disconnect /ID &quot;&amp;objResource.Name,1,True				

	End If 
Next</description>
		<content:encoded><![CDATA[<p>I managed to get what I wanted by the below code.  It closes all open files in the path specified on the server when run.  Hope this helps?</p>
<p>Dim Share </p>
<p>Set objConnection = GetObject(&#8220;WinNT://SERVERNAME/LanmanServer&#8221;)<br />
Set colSessions = objConnection.Sessions<br />
Set colResources = objConnection.Resources<br />
Set Shell = CreateObject(&#8220;WScript.Shell&#8221;)</p>
<p>On Error Resume Next</p>
<p>For Each objResource in colResources</p>
<p>	Share = left(objResource.Path,53)<br />
	If Share = &#8220;F:\Infrastructure\Snowinst2\AppData\Nielsen\database\&#8221; Then</p>
<p>		Shell.Run&#8221;OPENFILES /Disconnect /ID &#8220;&amp;objResource.Name,1,True				</p>
<p>	End If<br />
Next</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-348</link>
		<dc:creator>David</dc:creator>
		<pubDate>Mon, 25 Oct 2010 17:14:51 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-348</guid>
		<description>Many Thanks Niel!

Ashley - I was having the same issue as you and modified neils code to work for me,  I am getting strange errors but it still runs. I dont know enought about this kind of scripting to figure out why, but if anyone sees my error please let me know. I hope this helps someone.

@echo off
(set share=D:\LONGPATH\)
REM !! IMPORTANT set length in 4th from last line !!

FOR /f &quot;Skip=4 tokens=2,7&quot; %%i in (&#039;OPENFILES /Query /V&#039;) do (
 IF /I NOT &quot;%%i&quot;==&quot;The&quot; (
  call :checkpath %%i &quot;%%j&quot;
 )
)
pause
GOTO :EOF

:checkpath
 set id=%1
 set folder=%~2\
 :: !! The last number in the next line needs to
 :: be the length of the SHARE string
 SET root=%FOLDER:~0,40%
 IF /I NOT &quot;%ROOT%&quot;==&quot;%SHARE%&quot; GOTO :EOF
Echo %SHARE%
Echo %ROOT%
 echo %ID% is open on %FOLDER%. Closing...
NET FILE %id% /CLOSE</description>
		<content:encoded><![CDATA[<p>Many Thanks Niel!</p>
<p>Ashley &#8211; I was having the same issue as you and modified neils code to work for me,  I am getting strange errors but it still runs. I dont know enought about this kind of scripting to figure out why, but if anyone sees my error please let me know. I hope this helps someone.</p>
<p>@echo off<br />
(set share=D:\LONGPATH\)<br />
REM !! IMPORTANT set length in 4th from last line !!</p>
<p>FOR /f &#8220;Skip=4 tokens=2,7&#8243; %%i in (&#8216;OPENFILES /Query /V&#8217;) do (<br />
 IF /I NOT &#8220;%%i&#8221;==&#8221;The&#8221; (<br />
  call :checkpath %%i &#8220;%%j&#8221;<br />
 )<br />
)<br />
pause<br />
GOTO :EOF</p>
<p>:checkpath<br />
 set id=%1<br />
 set folder=%~2\<br />
 :: !! The last number in the next line needs to<br />
 :: be the length of the SHARE string<br />
 SET root=%FOLDER:~0,40%<br />
 IF /I NOT &#8220;%ROOT%&#8221;==&#8221;%SHARE%&#8221; GOTO :EOF<br />
Echo %SHARE%<br />
Echo %ROOT%<br />
 echo %ID% is open on %FOLDER%. Closing&#8230;<br />
NET FILE %id% /CLOSE</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashley</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-343</link>
		<dc:creator>Ashley</dc:creator>
		<pubDate>Thu, 11 Feb 2010 00:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-343</guid>
		<description>How about using OPENFILES instead of Net Files?  The OPENFILES /Query /V command gives the full path to the files.  I cannot seem to fit this in your script.  Can you help please ?</description>
		<content:encoded><![CDATA[<p>How about using OPENFILES instead of Net Files?  The OPENFILES /Query /V command gives the full path to the files.  I cannot seem to fit this in your script.  Can you help please ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-342</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Wed, 10 Feb 2010 14:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-342</guid>
		<description>Scratch the last line... it was late.

You&#039;ll need the SHARE variable to match the output of NET FILES if you need to restrict the files you close to a certain path (ie, not close all open files.)

If NET FILES is truncating your paths, you will need to use shorter ones, or the Script just isn&#039;t up to what you need it for. You would proably be better off looking into a WMI or PowerShell solution.</description>
		<content:encoded><![CDATA[<p>Scratch the last line&#8230; it was late.</p>
<p>You&#8217;ll need the SHARE variable to match the output of NET FILES if you need to restrict the files you close to a certain path (ie, not close all open files.)</p>
<p>If NET FILES is truncating your paths, you will need to use shorter ones, or the Script just isn&#8217;t up to what you need it for. You would proably be better off looking into a WMI or PowerShell solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashley</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-341</link>
		<dc:creator>Ashley</dc:creator>
		<pubDate>Wed, 10 Feb 2010 05:58:51 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-341</guid>
		<description>When setting SHARE can I use UNC path?  

How will this fix the issue because the NET FILES command is returning the compressed path?</description>
		<content:encoded><![CDATA[<p>When setting SHARE can I use UNC path?  </p>
<p>How will this fix the issue because the NET FILES command is returning the compressed path?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-340</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Wed, 10 Feb 2010 05:51:33 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-340</guid>
		<description>Ashley, I see what you mean about the compressed path. I expect you&#039;re hitting a limit of the net command.

My advice would be to try setting a shorter share (eg, \Database). Even if all you use it for is this script, it should work.</description>
		<content:encoded><![CDATA[<p>Ashley, I see what you mean about the compressed path. I expect you&#8217;re hitting a limit of the net command.</p>
<p>My advice would be to try setting a shorter share (eg, \Database). Even if all you use it for is this script, it should work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashley</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-339</link>
		<dc:creator>Ashley</dc:creator>
		<pubDate>Wed, 10 Feb 2010 04:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-339</guid>
		<description>Here is the extract of the logs after running the file:

C:\Documents and Settings\adm2sultana&gt;(set share=F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\ )  - is 53 including the /

C:\Documents and Settings\adm2sultana&gt;REM !! IMPORTANT set length in 4th from last line !!  

C:\Documents and Settings\adm2sultana&gt;FOR /F &quot;Skip=4 tokens=1,2&quot; %i in (&#039;NET FILES&#039;) do (IF /I NOT &quot;%i&quot; == &quot;The&quot; (call :checkpath %i &quot;%j&quot;  ) ) 

C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &quot;14232357&quot; == &quot;The&quot; (call :checkpath 14232357 &quot;F:\Infrastructure...V_CONFECTIONERY.IDX&quot;  ) )  - This one is a problem as it is not displaying the whole path and hence when trying to trim this to 53 charecters....it returns the same.

C:\Documents and Settings\adm2sultana&gt;set id=14232357  

C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure...V_CONFECTIONERY.IDX\  

C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure...V_CONFECTIONERY.IDX\   

C:\Documents and Settings\adm2sultana&gt;IF /I NOT &quot;F:\Infrastructure...V_CONFECTIONERY.IDX\  &quot; == &quot;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&quot; GOTO :EOF  

C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &quot;14232359&quot; == &quot;The&quot; (call :checkpath 14232359 &quot;F:\Infrastructure...V_CONFECTIONERY.TAD&quot;  ) ) 

C:\Documents and Settings\adm2sultana&gt;set id=14232359  

C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure...V_CONFECTIONERY.TAD\  

C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure...V_CONFECTIONERY.TAD\   

C:\Documents and Settings\adm2sultana&gt;IF /I NOT &quot;F:\Infrastructure...V_CONFECTIONERY.TAD\  &quot; == &quot;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&quot; GOTO :EOF  

C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &quot;14232360&quot; == &quot;The&quot; (call :checkpath 14232360 &quot;F:\Infrastructure...V_CONFECTIONERY.CHR&quot;  ) ) 

C:\Documents and Settings\adm2sultana&gt;set id=14232360  

C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure...V_CONFECTIONERY.CHR\  

C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure...V_CONFECTIONERY.CHR\   

C:\Documents and Settings\adm2sultana&gt;IF /I NOT &quot;F:\Infrastructure...V_CONFECTIONERY.CHR\  &quot; == &quot;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&quot; GOTO :EOF  

C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &quot;The&quot; == &quot;The&quot; (call :checkpath The &quot;command&quot;  ) ) 

C:\Documents and Settings\adm2sultana&gt;GOTO :EOF</description>
		<content:encoded><![CDATA[<p>Here is the extract of the logs after running the file:</p>
<p>C:\Documents and Settings\adm2sultana&gt;(set share=F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\ )  &#8211; is 53 including the /</p>
<p>C:\Documents and Settings\adm2sultana&gt;REM !! IMPORTANT set length in 4th from last line !!  </p>
<p>C:\Documents and Settings\adm2sultana&gt;FOR /F &#8220;Skip=4 tokens=1,2&#8243; %i in (&#8216;NET FILES&#8217;) do (IF /I NOT &#8220;%i&#8221; == &#8220;The&#8221; (call :checkpath %i &#8220;%j&#8221;  ) ) </p>
<p>C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &#8220;14232357&#8243; == &#8220;The&#8221; (call :checkpath 14232357 &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.IDX&#8221;  ) )  &#8211; This one is a problem as it is not displaying the whole path and hence when trying to trim this to 53 charecters&#8230;.it returns the same.</p>
<p>C:\Documents and Settings\adm2sultana&gt;set id=14232357  </p>
<p>C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure&#8230;V_CONFECTIONERY.IDX\  </p>
<p>C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure&#8230;V_CONFECTIONERY.IDX\   </p>
<p>C:\Documents and Settings\adm2sultana&gt;IF /I NOT &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.IDX\  &#8221; == &#8220;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&#8221; GOTO :EOF  </p>
<p>C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &#8220;14232359&#8243; == &#8220;The&#8221; (call :checkpath 14232359 &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.TAD&#8221;  ) ) </p>
<p>C:\Documents and Settings\adm2sultana&gt;set id=14232359  </p>
<p>C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure&#8230;V_CONFECTIONERY.TAD\  </p>
<p>C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure&#8230;V_CONFECTIONERY.TAD\   </p>
<p>C:\Documents and Settings\adm2sultana&gt;IF /I NOT &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.TAD\  &#8221; == &#8220;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&#8221; GOTO :EOF  </p>
<p>C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &#8220;14232360&#8243; == &#8220;The&#8221; (call :checkpath 14232360 &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.CHR&#8221;  ) ) </p>
<p>C:\Documents and Settings\adm2sultana&gt;set id=14232360  </p>
<p>C:\Documents and Settings\adm2sultana&gt;set folder=F:\Infrastructure&#8230;V_CONFECTIONERY.CHR\  </p>
<p>C:\Documents and Settings\adm2sultana&gt;SET root=F:\Infrastructure&#8230;V_CONFECTIONERY.CHR\   </p>
<p>C:\Documents and Settings\adm2sultana&gt;IF /I NOT &#8220;F:\Infrastructure&#8230;V_CONFECTIONERY.CHR\  &#8221; == &#8220;F:\Infrastructure\Snowinst2\AppData\Nielsen\DATABASE\&#8221; GOTO :EOF  </p>
<p>C:\Documents and Settings\adm2sultana&gt;(IF /I NOT &#8220;The&#8221; == &#8220;The&#8221; (call :checkpath The &#8220;command&#8221;  ) ) </p>
<p>C:\Documents and Settings\adm2sultana&gt;GOTO :EOF</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-338</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Wed, 10 Feb 2010 04:52:13 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-338</guid>
		<description>Ashley, I&#039;m not certain I understand the question; but try replacing the last three lines with these:

&lt;code&gt;Echo.
Echo %ROOT%*
Echo %SHARE%*&lt;/code&gt;

Then run it, and make sure the two strings are the same length. If not, adjust your &#039;53&#039; until they are. Chances are, you&#039;re not accounting for the &#039;\&#039;, and it needs to be 54 characters, or something similar.</description>
		<content:encoded><![CDATA[<p>Ashley, I&#8217;m not certain I understand the question; but try replacing the last three lines with these:</p>
<p><code>Echo.<br />
Echo %ROOT%*<br />
Echo %SHARE%*</code></p>
<p>Then run it, and make sure the two strings are the same length. If not, adjust your &#8217;53&#8242; until they are. Chances are, you&#8217;re not accounting for the &#8216;\&#8217;, and it needs to be 54 characters, or something similar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ashley</title>
		<link>http://caseelse.net/2008/05/17/how-to-close-open-files-on-a-server-share/comment-page-1/#comment-337</link>
		<dc:creator>Ashley</dc:creator>
		<pubDate>Wed, 10 Feb 2010 03:13:00 +0000</pubDate>
		<guid isPermaLink="false">http://neilbryant.net/articles/?p=3#comment-337</guid>
		<description>how to deal with long Paths to the Share?
net files displays  c:\share\â€¦\file

Set folder=%~2\ 

sets it to the filename within the folder i have set as SHARE eg:  C:\Share\Database So if a file by CAT.HDX is open within this folder the Folder variable gets set to that.

when I am setting root=%FOLDER:~0,53% i get the path with the filename set as root because the lenth of th epath is being displayed as indicated by Christian earlier.....

it never goes to closing the file as the IF command after that is never equal....

Can you please help....The length of my SHARE path is 53 characters.....

Thanks</description>
		<content:encoded><![CDATA[<p>how to deal with long Paths to the Share?<br />
net files displays  c:\share\â€¦\file</p>
<p>Set folder=%~2\ </p>
<p>sets it to the filename within the folder i have set as SHARE eg:  C:\Share\Database So if a file by CAT.HDX is open within this folder the Folder variable gets set to that.</p>
<p>when I am setting root=%FOLDER:~0,53% i get the path with the filename set as root because the lenth of th epath is being displayed as indicated by Christian earlier&#8230;..</p>
<p>it never goes to closing the file as the IF command after that is never equal&#8230;.</p>
<p>Can you please help&#8230;.The length of my SHARE path is 53 characters&#8230;..</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
</channel>
</rss>

