# bat file problem



## mpthimios (Jan 23, 2009)

Hi,
hope this is the correct forum. My problem:
I am trying to create a bat filr automate some updates on XP PCs. I check the installed windows version using:
ver | find "XP"

The problem is that the output is: 
The filename, directory name, or volume label syntax is incorrect.

I have tested this on other machines and it works! But not in mine..
if I run cmd.exe ver | find "XP" it works.
if I run ipconfig | find "Media" (for example) it works!

What am I possibly doing wrong?

Thanks,
Efthimios.


----------



## Squashman (Apr 4, 2003)

Why are you piping VER to the find command. The result is the same.
What happens when you use findstr
ver | findstr /c:XP


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!


mpthimios said:


> Hi,
> hope this is the correct forum. My problem:
> I am trying to create a bat filr automate some updates on XP PCs. I check the installed windows version using:
> ver | find "XP"
> ...


Are you typing this in a Command Prompt window, or is that line in a batch file?
If a batch file:


Is that the only line in the file?
Are you using .bat or .cmd extension?
How are you running it?
Type path\name in a Command Prompt window?
Type path\name in Run box?
Double click the file?




mpthimios said:


> I have tested this on other machines and it works! But not in mine..
> if I run cmd.exe ver | find "XP" it works.
> if I run ipconfig | find "Media" (for example) it works!


Again, are you typing this in a Command Prompt window, or putting these lines in a batch file?
What happens if you remove the pipe to Find, and just use *ver*?

I'm assuming your machine is running XP; if not, what OS are you running?

Jerry


----------



## mpthimios (Jan 23, 2009)

Hi,
I have tried most of the solutions you describe:
- typing ver | find "XP" in the command prompt (cmd.exe)
- executing through a .bat file (I call the .bat from the command prompt no double click)

The only case it works is if I enter: cmd.exe ver | find "XP". In this case a new instance of cmd opens. But I don't want this..

I am using XP and typing ver prints the version!
It is strange that pipe with ipconfig works. But not with ver or echo ...

-Efthimios.


----------



## TheOutcaste (Aug 8, 2007)

Very strange.


mpthimios said:


> The only case it works is if I enter: cmd.exe ver | find "XP".In this case a new instance of cmd opens


Does this actually open a 2nd Command Prompt window? When I do that command, I don't get a second window, but a 2nd instance is running. I have to type *Exit* to get back to a prompt.

Have you by any chance installed a Command Prompt replacement of any kind?

What happens if you leave the .exe part off? Type *cmd ver | find "XP"* and see if it works, or also fails.

How are you opening the Command Prompt:
From the icon on the start menu?
Typing *CMD* in the *Start | Run* box?

Try this, open the Command Prompt this way:
*Start | Run*, type *%windir%\system32\cmd.exe*, press *Enter*, see if that makes any difference.

As a workaround, you can use this in a batch file to check if you are running XP. The IsXP variable will only be set to XP if the fiind is successful:


```
Set IsXP=NotXP
cmd.exe /c ver | find "XP">Nul && Set IsXP=XP
If %IsXP%==NotXP Goto NotXP
```
Jerry


----------

