1.

Solve : Close Open Network Files?

Answer»

Hi I am trying to write a batch to close open network files before I upgrade my program.  What I need to do is...

Code
net files > net.txt
type net.txt | find "Myprog.exe"

From here this will usually produce a list from find like so.. what I need to do is take the ID # 1125 and use the "Net Files 1125 /close" command to close each ID anyone have an idea how I could do this?
_______________________________________ ________
ID       Files                                 USER

1125  c:\program\Myprog.exe         JOE
1126  c:\program\Myprog.exe         JACK
1127  c:\program\Myprog.exe         JIM
1128  c:\program\Myprog.exe
1154  c:\program\Myprog.exe
1178  c:\program\Myprog.exe
1189  c:\program\Myprog.exe
1190  c:\program\Myprog.exe
1197  c:\program\Myprog.exe
_______________________________________ ________
can you GET the ID number in a text file? if so this will close the files:

Code: [Select]for /f "tokens=* delims=" %%A in ('type textfile.txt') do (
net files %%A /close
)
exit
Or if you can get the above output to be piped to a text file the top line would look like:
Code: [Select]for /f "tokens=1-2 delims= " %%A in ('type textfile.txt ^| find "myprog.exe"') do (
...

FB Code: [Select]echo off
net files > net.txt
for /F "delims= " %%a in ('type net.txt ^|findstr "Myprog.exe"') do (
Net Files %%a /close
)
pause >nul
try this one Quote from: fireballs on August 30, 2008, 12:48:42 PM

can you get the ID number in a text file? if so this will close the files:

Code: [Select]for /f "tokens=* delims=" %%A in ('type textfile.txt') do (
net files %%A /close
)
exit
Or if you can get the above output to be piped to a text file the top line would look like:
Code: [Select]for /f "tokens=1-2 delims= " %%A in ('type textfile.txt |^ find "myprog.exe"') do (
...

FB

Code: [Select]net files > net.txt
for /f "tokens=1-2 delims= " %%A in ('type net.txt |^ find "myprog"') do (
Net Files %%a /close
exit
This is the output from net.txt
-------------------------------------------------------------------------------------------------------
ID         Path                                    User name            # Locks

--------------------------------------------------------------------------------------------------
994        C:\myprog\...\mgxerces-c_2_6.dll         RAPSTER               0     
1104       C:\myprog                                RAPSTER               0     
1105       C:\myprog                                RAPSTER               0     
1126       C:\myprog\...\mgicuuc32.dll              RAPSTER               0     
1127       C:\myprog\...\mgicudt32.dll              RAPSTER               0     
1128       C:\myprog\...\MGmerge.dll                RAPSTER               0     
1129       C:\myprog\...\MGrqgnrc94.dll             RAPSTER               0     
1130       C:\myprog\...\MG_OCX.DLL                 RAPSTER               0     
1131       C:\myprog\...\mgrqsoap.dll               RAPSTER               0     
1133       C:\myprog\...\mgresrc.dll                RAPSTER               0     
1138       C:\myprog\...\GATEWAYS\MGMS7.DLL         RAPSTER               0     
1139       C:\myprog\...\GATEWAYS\MGMEMORY.DLL      RAPSTER               0     
1141       C:\myprog\...\LIBEAY32.dll               RAPSTER               0     
1169       C:\myprog\...\AMSPROD92704sp8.MFF        RAPSTER               0     
1177       C:\myprog\...\mglock1.dat                RAPSTER               0     
The command completed successfully.
_______________________________________ ________________________


I tried this but it said "%%A was unexpected at this time"

I am not sure how this command works but I may have type it wrong? Quote from: devcom on August 30, 2008, 12:53:22 PM
Code: [Select]echo off
net files > net.txt
for /F "delims= " %%a in ('type net.txt ^|findstr "Myprog.exe"') do (
Net Files %%a /close
)
pause >nul
try this one

I tried this one to but it is prob the way i explained it and that I don't really know what this code is doing so I may have explained and or miss typed thecode when I tried itBased on your listing, you need to match myprog not myprog.exe

Code: [Select]echo off
for /f %%a in ('net files ^| find /i "myprog"') do (
net files %%a /close
)
pause > nul

 

Quote from: Sidewinder on August 30, 2008, 03:00:23 PM
Based on your listing, you need to match myprog not myprog.exe

Code: [Select]echo off
for /f %%a in ('net files ^| find /i "myprog"') do (
net files %%a /close
)
pause > nul

 



The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need SOMETHING to kill the ID Number

Code: [Select]net files IDnumberhere /close

In the txt file that net files > net.txt grabs the ID is random for each file that is open by the user...

net.txt
------------------------------------------------------------------------------------
ID
994        C:\myprog\...\mgxerces-c_2_6.dll         RAPSTER               0     
1104       C:\myprog                                RAPSTER               0     

Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 

Quote from: Sidewinder on August 30, 2008, 03:55:01 PM
Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 



C:\Documents and Settings\Administrator\Desktop>
Code: [Select]net files > net.txt
Code: [Select]for /f %%a in ('net.txt ^| find /i "myprog"') do (net files %%a /close)
Result
%%a was unexpected at this time.

Closing the files has never hurt anything before we are replacing all the files they are using in the "myprog" folder at the time of the upgrade but most people go home at the end of the day leaving the program open

Did I type the code wrong? that is the result I got from RUNNING it.. And thanks for working with me on this to everyone... I apologize for my minimal skill in code.... Quote from: rmathes on August 30, 2008, 04:33:34 PM
Quote from: Sidewinder on August 30, 2008, 03:55:01 PM
Quote
The reason for looking for myprog is because the app is in that folder and the users well be accessing alot of files from there so the net files will list all open files to the txt file which is good but once its in that file I need something to kill the ID Number

Understood.

net file - Displays all the open shared files on a server and the lock-id
net file id /close - Close a shared file (disconnect other users and remove file locks)

Code: [Select]echo off
for /f %%a in ('net file ^| find /i "myprog"') do (
net file %%a /close
)
pause

Does the above code work? Might be better to copy/paste rather than re-type.

Doesn't closing shared files make the executing program unstable?

 



C:\Documents and Settings\Administrator\Desktop>
Code: [Select]net files > net.txt
Code: [Select]for /f %%a in ('net.txt ^| find /i "myprog"') do (net files %%a /close)
Result
%%a was unexpected at this time.

Closing the files has never hurt anything before we are replacing all the files they are using in the "myprog" folder at the time of the upgrade but most people go home at the end of the day leaving the program open

Did I type the code wrong? that is the result I got from running it.. And thanks for working with me on this to everyone... I apologize for my minimal skill in code....
User Error.... I did the copy paste this time... the code works as it should !! Thanks a bunch.,,,


Discussion

No Comment Found