Scripting question

M

Marc Meltzer

I am trying to run a simple script in an environment that has both Windows
Vista and Windows 2000:

----- script below -----
if %os_version% == 5.0.2195 goto W2k

:Vista
echo "Windows Vista"
got End

:W2k
echo "Windows 2000"

:End
----- end script -----

This runs fine on Windows 2000, but in Vista I get the error "goto was
unexpected at this time"

If I remove the %%, then the script runs, although it never evaluates
properly. I guess the question is how can I run this script on both OSes so
it evaluates properly?

Thanks,
Marc
 
Z

Zaphod Beeblebrox

Marc Meltzer said:
I am trying to run a simple script in an environment that has both
Windows Vista and Windows 2000:

----- script below -----
if %os_version% == 5.0.2195 goto W2k

:Vista
echo "Windows Vista"
got End

:W2k
echo "Windows 2000"

:End
----- end script -----

This runs fine on Windows 2000, but in Vista I get the error "goto was
unexpected at this time"

If I remove the %%, then the script runs, although it never evaluates
properly. I guess the question is how can I run this script on both
OSes so it evaluates properly?

Since by default Vista (and XP for that matter) do not have an
environment variable called OS_VERSION, unless you are setting it
yourself the statement 'if %os_version% == 5.0.2195 goto W2k' evaluates
to 'if == 5.0.2195 goto W2k', which is an incomplete statement and
causes your error. The fix is easy - enclose both sides of the
expression in quotes like this (and incidentally, remove the spaces
around the == which can also cause problems):

if "%os_version%"=="5.0.2195" goto W2k

That way, a blank OS_VERSION causes the statement to evaluate to 'if
""=="5.0.2195" goto W2k', which won't cause the error.
 
T

Tim Quan [MSFT]

Hi,

As your issue is related to scripting, we are not the best resource to
troubleshoot it in this Windows Vista newsgroup.

I suggest discussing this issue in our MSDN newsgroup:

MSDN newsgroups
http://msdn.microsoft.com/newsgroups/default.asp

I hope this information is helpful in getting started and we invite you to
post again with any specific break/fix issues.

Sincerely,
Tim Quan
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

With newsgroups, MSDN subscribers enjoy unlimited, free support as opposed
to the limited number of phone-based technical support incidents. Complex
issues or server-down situations are not recommended for the newsgroups.
Issues of this nature are best handled working with a Microsoft Support
Engineer using one of your phone-based incidents.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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