A file that exists only on XP?

G

Guest

Hello,

I am doing a batch file with an "if exist" statement so I can ensure that
the script goes to XP boxes and not servers. I am looking to check for the
presence of a file which would only be present on an XP box but not server.

Can anyone suggest a file that I could use for this?
 
J

John John - MVP

Maybe you could use the results of the VER command instead of relying on
the presence of files.

John
 
P

Pegasus [MVP]

Hello,

I am doing a batch file with an "if exist" statement so I can ensure that
the script goes to XP boxes and not servers. I am looking to check for
the presence of a file which would only be present on an XP box but not
server.

Can anyone suggest a file that I could use for this?

Instead of looking for a file that exists/does not exist, consider using a
command that reports specifically what type of machine you're on. Here are
two of them:

@echo off
ver
net accounts | find /i "role"
 
G

Guest

I agree that's probably better I just don't know how to work that into the
IF statement...
 
P

Pegasus [MVP]

@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation
 
T

Tim Meddick

Pegasus,
I don't understand how Mr dash finds success in :

@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation

???

....since the output of the ver command (on my machine at least) is :

Microsoft Windows XP [Version 5.1.2600]

....so [find /i "XP Workstation"] would not work!!


Please clarify this for me.

==

Cheers, Tim Meddick, Peckham, London. :)
 
P

Pegasus [MVP]

I suspect that Mr. dash did not religiously copy my code but modified it
like so:

ver | find /i "Windows XP"

in order to compensate for my mistake in mixing the output from the two
commands
ver
net accounts

Thanks for pointing out my error! :)


Tim Meddick said:
Pegasus,
I don't understand how Mr dash finds success in :

@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation

???

...since the output of the ver command (on my machine at least) is :

Microsoft Windows XP [Version 5.1.2600]

...so [find /i "XP Workstation"] would not work!!


Please clarify this for me.

==

Cheers, Tim Meddick, Peckham, London. :)




Pegasus said:
@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation
 
T

Tim Meddick

Thanks - I wasn't trying to be "clever" or point out mistakes - I
genuinely did not know if I was missing something.

Thankyou again for clarification.

==

Cheers, Tim Meddick, Peckham, London. :)




Pegasus said:
I suspect that Mr. dash did not religiously copy my code but modified
it like so:

ver | find /i "Windows XP"

in order to compensate for my mistake in mixing the output from the
two commands
ver
net accounts

Thanks for pointing out my error! :)


Tim Meddick said:
Pegasus,
I don't understand how Mr dash finds success in :

@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation

???

...since the output of the ver command (on my machine at least) is :

Microsoft Windows XP [Version 5.1.2600]

...so [find /i "XP Workstation"] would not work!!


Please clarify this for me.

==

Cheers, Tim Meddick, Peckham, London. :)




Pegasus said:
@echo off
ver | find /i "XP Workstation"
if %ErrorLevel% EQU 0 echo This is a WinXP Workstation


<-> wrote in message I agree that's probably better I just don't know how to work that
into the IF statement...


<-> wrote in message Hello,

I am doing a batch file with an "if exist" statement so I can
ensure that the script goes to XP boxes and not servers. I am
looking to check for the presence of a file which would only be
present on an XP box but not server.

Can anyone suggest a file that I could use for this?

Instead of looking for a file that exists/does not exist, consider
using a command that reports specifically what type of machine
you're on. Here are two of them:

@echo off
ver
net accounts | find /i "role"
 
P

Pegasus [MVP]

I'm actually glad you noticed my mistake. This is one of the advantages of
newsgroup: Peer review. It increases the confidence level for posters who
may otherwise attempt to implement a useless or damaging solution to their
problem.
 
G

Guest

This is what I used:

echo on
ver | find "5.1"
if not errorlevel 1 (
CALL \\server1\share\batchfile1.cmd
) else (
goto :eof
)


@Shenan - This was not a Google situation. I initially was trying to find a
file that existed only on XP and after Googling extensively could not find a
lock. I posted here, and an alternate suggestion was offered. I know how
to search Google, that's how I found the syntax for this code to select
"5.1" But thanks for bringing it up.
 
P

Pegasus [MVP]

Looks good. You could simplify it further, if only because the logic is a
lot easier to understand than the double negative you're forced to use in
your implementation:

echo on
ver | find "5.1" || goto :eof
call \\Server\share\batchfile1.cmd
 
G

Guest

You're right that is easier. Of course, I just put it into production today
so at this point I won't even breathe on it.

Thanks again for your help!
 
T

Tim Meddick

Pegasus,
I had major problems testing the code you posted - it was
some time before I worked out that the cause was not your script but the
character set.

On 'copying and pasting' your posted script, the "bar" redirectional
character did not come out as 0x7C but came out as 0xDD instead thus
wrecking the functionality of the batch file.

Just thought you might like to know as it might be a bit of a hazard if
it were code given to help someone who was not so well acquainted with
batch programming as Mr dash...

==

Cheers, Tim Meddick, Peckham, London. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top