Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Vista General Discussion > Scripting question

Reply
Thread Tools Display Modes

Scripting question

 
 
Marc Meltzer
Guest
Posts: n/a

 
      12-19-2008
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

 
Reply With Quote
 
 
 
 
Zaphod Beeblebrox
Guest
Posts: n/a

 
      12-19-2008

"Marc Meltzer" <> wrote in message
news:A99E248F-356D-4F59-87BC-...
>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.

--
Zaphod

No matter where you go, there you are!



 
Reply With Quote
 
Tim Quan [MSFT]
Guest
Posts: n/a

 
      12-22-2008
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/subscripti...ult.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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UAC and scripting sputnik Windows Vista General Discussion 1 05-08-2008 03:21 PM
WAIK 1.1 Scripting Error TonyB_EDS Windows Vista Installation 0 04-29-2008 03:56 PM
scripting moviemaker... iamsam Windows Vista Music, Pictures and Video 1 03-24-2008 09:20 PM
Re: Sidebar corruption, IE scripting does not work Jane C Windows Vista General Discussion 6 08-11-2007 11:55 AM
Scripting performance setting Or Tsemah Windows Vista Performance 0 05-29-2007 11:55 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59