Find a File

Easily check every machine on your network for a particular file.

Readers

January 26, 2003

2 Min Read
ITPro Today logo

Occasionally, I need to check every server and workstation on my network for a particular file or process. This task takes a long time because we have a lot of machines. In addition, performing such a search uses valuable network bandwidth and ruins my computer's performance. I decided that a better method was to have each machine check itself and report any results to me.

First, create on a server a share called \MyServerNewShare that has read and write access for the Everyone group. You must use a server because Windows 2000 Professional and Windows NT Workstation's 10-user limits will create a problem. Next, add the share name to the HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesLanmanServerParametersNullSessionShares REG_MULTI_SZ registry entry. Perform this step manually so that you don't overwrite existing settings. A null session share is necessary to let the local System account that the scheduler service uses connect over the network to remote shares.

Create two directories named \MyServerNewShareTools and \MyServerNewShareResults in the share. Give the Tools directory Everyone:R permissions and the Results directory Everyone:RW permissions. If you don't set the Tools directory to read-only, anyone connected to your network can change the directory's contents.

In the \MyServerNewShareTools directory, create the batch file

Rem GetInfo.batdir /s /b c:FileToFind.txt > MyServerNewShareResults%COMPUTERNAME%.txtexit

On all the computers you want to check, schedule the command

at \AnyComputer 12:00 \MyServerNewShareTools GetInfo.bat

After this command runs, you'll have a list in the \MyServerNewShareResults directory of all the computers on which the file FileToFind.txt exists.

You can modify the GetInfo.bat file to administer or analyze almost any process that takes a while to run. For example, I have a program that does a bit-by-bit cyclical redundancy check (CRC) of 10GB of data and publishes any errors in my Results directory. However, you need to be careful because the GetInfo.bat file might cause a disaster if you use it incorrectly. For example, I used a similar batch file to search for and delete a file on all my company's servers—imagine what could have gone wrong if I had deleted an important file.

To run the check at 12:00 on all the computers in your domain, use the code

for /f "delims= " %i in ('net view ^| findstr  ') do at \%i 12:00 \MyServerNewShareTools GetInfo.bat

Don't forget to use double percent signs (i.e., %%) in batch files.

To organize into one file all the FileToFind.txt entries in the \MyServerNewShareResults directory, use the command

findstr "FileToFind.txt"   \MyServerNewShareResults  *.txt > c:all.txt

—Stephen Hulse
[email protected]

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like