Can anybody please tell me what the following commands are doing? this
is a cmd logon script

subst m: /d >nul 2>&1
subst m: h:\notes_crb >nul 2>&1

Re: Subst question by Steve

Steve
Sun Feb 20 05:32:51 CST 2005

Rick wrote:

> Can anybody please tell me what the following commands are doing? this
> is a cmd logon script
>
> subst m: /d >nul 2>&1
> subst m: h:\notes_crb >nul 2>&1

Subst
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx

Command-line reference A-Z
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx

--
Steve

There are some things so serious you have to laugh at them.
-Niels Henrik David Bohr

Re: Subst question by Rick

Rick
Sun Feb 20 08:02:49 CST 2005

Great stuff, thanks

On Sun, 20 Feb 2005 06:32:51 -0500, "Steve Fulton"
<cerberus40@hotmail.com> wrote:

>Rick wrote:
>
>> Can anybody please tell me what the following commands are doing? this
>> is a cmd logon script
>>
>> subst m: /d >nul 2>&1
>> subst m: h:\notes_crb >nul 2>&1
>
>Subst
>http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx
>
>Command-line reference A-Z
>http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx
>
>--


Re: Subst question by Rick

Rick
Sun Feb 20 09:00:23 CST 2005

ok I understand what the subst command does, can you tell me what the
>nul 2>&1 is doing?

thanks in advance

R
On Sun, 20 Feb 2005 06:32:51 -0500, "Steve Fulton"
<cerberus40@hotmail.com> wrote:

>Rick wrote:
>
>> Can anybody please tell me what the following commands are doing? this
>> is a cmd logon script
>>
>> subst m: /d >nul 2>&1
>> subst m: h:\notes_crb >nul 2>&1
>
>Subst
>http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/subst.mspx
>
>Command-line reference A-Z
>http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx


Re: Subst question by Matthias

Matthias
Sun Feb 20 09:23:30 CST 2005

Rick wrote:
> ok I understand what the subst command does, can you tell me what the
>
>>nul 2>&1 is doing?
>
> thanks in advance

Hi Rick.

Please remove unnecessary full quotes.

The >NUL redirects console (or standard) output to device NUL which
you can view as a black hole ;-)

2>&1 combines the error output of a program to the same destination.

This guaranties that any output of the program is hidden.

HTH


--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+

Re: Subst question by Rick

Rick
Sun Feb 20 10:07:31 CST 2005

Thank you

On Sun, 20 Feb 2005 16:23:30 +0100, Matthias Tacke <Matthias@Tacke.de>
wrote:

>Rick wrote:
>> ok I understand what the subst command does, can you tell me what the
>>
>>>nul 2>&1 is doing?
>>
>> thanks in advance
>
>Hi Rick.
>
>Please remove unnecessary full quotes.
>
>The >NUL redirects console (or standard) output to device NUL which
>you can view as a black hole ;-)
>
>2>&1 combines the error output of a program to the same destination.
>
>This guaranties that any output of the program is hidden.
>
>HTH


Re: Subst question by Rick

Rick
Sun Feb 20 11:12:35 CST 2005

I have another question maybe you could help me with, the following
line

@if not "%OS%"=="Windows_NT" (goto :LOGOFF)

is this say if the OS is NOT Windows NT(XP) go to logoff or IS Windows
XP?

thanx

On Sun, 20 Feb 2005 16:23:30 +0100, Matthias Tacke <Matthias@Tacke.de>
wrote:

>Rick wrote:
>> ok I understand what the subst command does, can you tell me what the
>>
>>>nul 2>&1 is doing?
>>
>> thanks in advance
>
>Hi Rick.
>
>Please remove unnecessary full quotes.
>
>The >NUL redirects console (or standard) output to device NUL which
>you can view as a black hole ;-)
>
>2>&1 combines the error output of a program to the same destination.
>
>This guaranties that any output of the program is hidden.
>
>HTH


Re: Subst question by Roland

Roland
Sun Feb 20 15:27:43 CST 2005

"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



Re: Subst question by Al

Al
Sun Feb 20 19:09:07 CST 2005


"Roland Hall" <nobody@nowhere> wrote in message
news:uBg8EM5FFHA.1296@TK2MSFTNGP10.phx.gbl...
> "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

As an aside, I do not think this works for 9x.

> I've never seen the () around a goto statement and : is not needed
although
> that is the way you make a label.

Parentheses are used to group a set of commands to create a compound
command. The set of commands must number AT LEAST ONE. I don't use it for
single goto's like that, but I sometimes use it like this:

(set var=no trailing blanks here!)

To ensure that I do not inadvertently have a trailing blank included in the
variable.

> Ex.
>
> @echo off
> if not "%OS%"=="Windows_NT" goto LOGOFF

Also, I prefer to explicitly keep the ":" in the name of the label, i.e.:

goto:LOGOFF

This serves to make all references to labels syntactically consistent, i.e.:

call:mySub arg1 arg2

> .
> .
> .
> :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.

UNLESS the SET command is used to modify its value.

> 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.

Erm, it wouldn't fail, it would just detect an inequality. That would be a
success, as the purpose would be to avoid running code that is not designed
for the o/s in effect.

And, while non-NT o/s's that run batch files generally do not set the OS
variable to anything, this does not prevent one's script from setting it to,
for example, "Windows98". We had a huge problem at one site where the
standard 98 client was modified to set this value in the autoexec.bat file
(the guy who did this left without documenting it). A later change to the
logon script, where they tested for "", came to the wrong conclusion as to
the O/S and it took a week to find the cause.

/Al

> "" == "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
>
>