| 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... can you get the ID number in a text file? if so this will close the files: 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 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 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 QuoteThe 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 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 PMUser Error.... I did the copy paste this time... the code works as it should !! Thanks a bunch.,,,QuoteThe 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 |
|