# Batch File - Pulling an IP from a list?



## Rawns (May 8, 2009)

I would like to create a batch file that connects to a number of servers one at a time, checks the version of an EXE file and writes the version number to a log file. 

The plan is to have the batch file, a text file with the server IP addresses listed (about 200 or so) and the log file. The idea is I can just add other servers to the file as and when. 

Any advice how I could do this? I'm rather new to batch files!


----------



## MysticPixie (May 5, 2009)

If the executable you are checking creates a registry key with it's version information you can extract it from there using a registry query.

If you happen to know roughly where the registry key is, it shouldn't be too terribly difficult. As I recently discovered though, I'm a bit rusty with batch.

As for parsing a list of IPs, that's easy. A "For" loop can take care of that. If the list contains ONLY IP addresses, it's super easy. If the list contains other information, as long as the formatting is consistent, it's still easy, just requires a bit more information in the "For" loop.


```
For /f %%i in yourtextfile.txt Do whatever
```
Do you currently have anything written?


----------



## Squashman (Apr 4, 2003)

Need parentheses.

```
For /F "tokens=*" %%I IN [color=red]([/color]IpAddressList.txt[color=red])[/color] DO (
    Put the rest of your code here
    )
```
Not sure how you are going to get the file version. You can use PStools to connect to the remote computers. Now if there is a command line tool that can get the file version you can just add that into the for loop.


----------



## Squashman (Apr 4, 2003)

Just realized XP comes with FILEVER. If that is what you are looking for.
I would assume that utility is on all your servers. If not you can just use PSEXEC to copy it over and execute it on the remote computer.


----------



## MysticPixie (May 5, 2009)

You sure squash? I didn't see anything here:

http://technet.microsoft.com/en-us/library/bb490890.aspx#EQAA

Is it one that's not documented?


----------



## TheOutcaste (Aug 8, 2007)

filever.exe is part of the XP SP2 Support Tools, which can be downloaded from here:Windows XP Service Pack 2 Support Tools

It's also included with the Win2k3 Server Support tools that are on the CD.

It should also be included with the latest version which can be downloaded from here:
Windows Server 2003 Service Pack 2 32-bit Support Tools

With filever.exe it should be easy to get file version information in a batch file.

It supports UNC paths, so no need to copy to the other systems:

```
filever \\192.168.9.4\c$\winnt\system32\event*.exe
```
HTH

Jerry


----------



## Squashman (Apr 4, 2003)

MysticPixie said:


> You sure squash? I didn't see anything here:
> 
> http://technet.microsoft.com/en-us/library/bb490890.aspx#EQAA
> 
> Is it one that's not documented?


You need parentheses around the set. In this case, around the filename with the IP addresses.


----------

