Re: Subst question
From: Roland Hall (nobody_at_nowhere)
Date: 02/20/05
- Previous message: Roland Hall: "Re: Login script with admin priveleges"
- In reply to: Rick: "Re: Subst question"
- Next in thread: Al Dunbar [MS-MVP]: "Re: Subst question"
- Reply: Al Dunbar [MS-MVP]: "Re: Subst question"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 20 Feb 2005 15:27:43 -0600
"Rick" <None@none.com> wrote in message
news:u5hh11d6q5daodebc2esfnt3ohc8618fup@4ax.com...
:I have another question maybe you could help me with, the following
: line
:
: @if not "%OS%"=="Windows_NT" (goto :LOGOFF)
In a batch file, the @ symbol at the beginning of a line will hide the line
from being displayed. It is equivalent or == to Echo off. Perhaps you've
seen @Echo Off. The @ hides the first line and then Echo Off hides the rest
of them.
The ==, as stated above is the equivalent so the user is looing for an
environment variable, which you can see at a command prompt when you type
in: set. This will show you all environment variables. However, you can
also limit it to one easily if you type in: echo %OS%
Doing this on my XP system I get:
c:\>echo %OS%
Windows_NT
I've never seen the () around a goto statement and : is not needed although
that is the way you make a label.
Ex.
@echo off
if not "%OS%"=="Windows_NT" goto LOGOFF
.
.
.
:LOGOFF
echo Thanks for visiting Wally World.
echo See you next year!
:
: is this say if the OS is NOT Windows NT(XP) go to logoff or IS Windows
: XP?
Windows NT, 2K and XP all show Windows_NT because they are based on it.
The other thing you may not have noticed was the "" around %OS% and
Windows_NT.
Double quotes are generally put around paths, variable names when spaces are
present so the variable or path is not parsed and is taken as whole.
However, it was not used like that here. If this batch file was run on an
OS not based on Windows NT, then it would not be equivalent to Windows_NT,
which means it would return a blank value. You cannot test a blank value so
the double quotes provide a value > blank.
Ex. If the OS was something else it would return "" and the test would
fail.
"" == "Windows_NT"? fails and would then make the statement true and branch
to LOGOFF. If it were based on Windows NT, it would return false because
"Windows_NT" == "Windows_NT".
If the quotes were missing and this was run on say, Windows 98, I don't
think there is an OS environment variable so it would return blank and that
would case the batch process to error.
I do mine a little different but with the same concept in mind.
@echo off
if not /%OS% == /Windows_NT goto LOGOFF
.
.
.
:LOGOFF
Hope that clears it up.
-- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */ Technet Script Center - http://www.microsoft.com/technet/scriptcenter/ WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp MSDN Library - http://msdn.microsoft.com/library/default.asp
- Previous message: Roland Hall: "Re: Login script with admin priveleges"
- In reply to: Rick: "Re: Subst question"
- Next in thread: Al Dunbar [MS-MVP]: "Re: Subst question"
- Reply: Al Dunbar [MS-MVP]: "Re: Subst question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|