Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NET SEND related question... 1

Status
Not open for further replies.

ratbs75

IS-IT--Management
Joined
Mar 8, 2001
Messages
147
Location
BE
Hi,

I want to create a batch which send 5 times the same msg... BUT, there must be an IF... cause if the first msg can't go through because of broken connection, I don't need to try out the other 4 msg... thnx for help....

I know the I got an error message when doing a NET SEND ... which doesn't find the destination for any reason, but how to get this into an IF command?
thnx

 
Have you tried Help IF at command prompt? Here's the help on IF from win2k (pretty sure same as NT)

If
Performs conditional processing in batch programs. If the condition specified in an if command is true, Windows 2000 carries out the command that follows the condition. If the condition is false, Windows 2000 ignores the command in the if clause, and executes any command in the else clause, if one has been specified.

if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist filename command [else expression]

With command extensions enabled:

if [/i] string1 compare-op string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]

Parameters

not

Specifies that Windows 2000 should carry out the command only if the condition is false.

errorlevel number

Specifies a true condition only if the previous program run by Cmd.exe returned an exit code equal to or greater than number.

command

Specifies the command that Windows 2000 should carry out if the preceding condition is met.

string1==string2

Specifies a true condition only if string1 and string2 are the same. These values can be literal strings or batch variables (%1, for example). Literal strings do not need quotation marks.

exist filename

Specifies a true condition if filename exists.

compare-op

one of the following three-letter comparison operators:

Operator Description
EQU equal to
NEQ not equal to
LSS less than
LEQ less than or equal to
GTR greater than
GEQ greater than or equal to

/i

The /i switch, when specified, forces string comparisons to ignore case. The /i switch can also be used on the string1==string2 form of if. These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed.

cmdextversion number

The cmdextversion conditional works just like errorlevel, except it is comparing against an internal version number associated with the Command Extensions feature of Cmd.exe. The first version is 1. It will be incremented by one when significant enhancements are added to the command extensions. The cmdextversion conditional is never true when command cxtensions are disabled.

defined variable

The defined conditional works just like exist except it takes an environment variable name and returns true if the environment variable is defined. Three variables are added with this conditional: %errorlevel%, %cmdcmdline%, and %cmdextversion%.

%errorlevel% expands into a string representation of the current value of errorlevel, provided that there is not already an environment variable with the name ERRORLEVEL, in which case you will get its value instead. After running a program, the following illustrates errorlevel use:

goto answer%erorlevel%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1
You can also use the comparison operators listed above at compare-op:

if %errorlevel% LEQ 1 goto okay
%cmdcmdline% expands into the original command line passed to Cmd.exe prior to any processing by Cmd.exe, provided that there is not already an environment variable with the name cmdcmdline, in which case you will get its value instead.

%cmdextversion% expands into the a string representation of the current value of cmdextversion, provided that there is not already an environment variable with the name CMDEXTVERSION, in which case you will get its value instead.

expression

In an else clause, an expression consists of a Windows 2000 command and any parameters to be passed to the command.

 
Have you tried Help IF at command prompt? Here's the help on IF from win2k (pretty sure same as NT)

If
Performs conditional processing in batch programs. If the condition specified in an if command is true, Windows 2000 carries out the command that follows the condition. If the condition is false, Windows 2000 ignores the command in the if clause, and executes any command in the else clause, if one has been specified.

if [not] errorlevel number command [else expression]

if [not] string1==string2 command [else expression]

if [not] exist filename command [else expression]

With command extensions enabled:

if [/i] string1 compare-op string2 command [else expression]

if cmdextversion number command [else expression]

if defined variable command [else expression]

Parameters

not

Specifies that Windows 2000 should carry out the command only if the condition is false.

errorlevel number

Specifies a true condition only if the previous program run by Cmd.exe returned an exit code equal to or greater than number.

command

Specifies the command that Windows 2000 should carry out if the preceding condition is met.

string1==string2

Specifies a true condition only if string1 and string2 are the same. These values can be literal strings or batch variables (%1, for example). Literal strings do not need quotation marks.

exist filename

Specifies a true condition if filename exists.

compare-op

one of the following three-letter comparison operators:

Operator Description
EQU equal to
NEQ not equal to
LSS less than
LEQ less than or equal to
GTR greater than
GEQ greater than or equal to

/i

The /i switch, when specified, forces string comparisons to ignore case. The /i switch can also be used on the string1==string2 form of if. These comparisons are generic, in that if both string1 and string2 are both comprised of all numeric digits, then the strings are converted to numbers and a numeric comparison is performed.

cmdextversion number

The cmdextversion conditional works just like errorlevel, except it is comparing against an internal version number associated with the Command Extensions feature of Cmd.exe. The first version is 1. It will be incremented by one when significant enhancements are added to the command extensions. The cmdextversion conditional is never true when command cxtensions are disabled.

defined variable

The defined conditional works just like exist except it takes an environment variable name and returns true if the environment variable is defined. Three variables are added with this conditional: %errorlevel%, %cmdcmdline%, and %cmdextversion%.

%errorlevel% expands into a string representation of the current value of errorlevel, provided that there is not already an environment variable with the name ERRORLEVEL, in which case you will get its value instead. After running a program, the following illustrates errorlevel use:

goto answer%erorlevel%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1
You can also use the comparison operators listed above at compare-op:

if %errorlevel% LEQ 1 goto okay
%cmdcmdline% expands into the original command line passed to Cmd.exe prior to any processing by Cmd.exe, provided that there is not already an environment variable with the name cmdcmdline, in which case you will get its value instead.

%cmdextversion% expands into the a string representation of the current value of cmdextversion, provided that there is not already an environment variable with the name CMDEXTVERSION, in which case you will get its value instead.

expression

In an else clause, an expression consists of a Windows 2000 command and any parameters to be passed to the command.

 
THANK you very much , It helped :)

thnx again
 
Any chance you could show us how you did with the script.. Regards

Yardyy
 
So, for your batch file, you might have something like:

@echo off
net send * Message
if errorlevel=1 goto error
net send * Message
net send * Message
net send * Message
:error
 
My error code returns 2 when a net send can't operate (sorry, I'm under XP not NT.... :) ) Here a portion of the batch... I'm pretty sure I could use a WHILE or UNTIL boucle or whatever, but as I wrote that already that way, I didn't changed it... :)
The IF statement is only to prevent to wait when he can't 'net send' to a user... goes faster ;)


net send USER0 EOD in 5 MINUTES, make SURE blablabla
if %errorlevel% EQU 2 goto next1
net send USER0 EOD in 5 MINUTES, make SURE blablabla
net send USER0 EOD in 5 MINUTES, make SURE blablabla

:next1
net send USER1 EOD in 5 MINUTES, make SURE blablabla
if %errorlevel% EQU 2 goto next2
net send USER1 EOD in 5 MINUTES, make SURE blablabla
net send USER1 EOD in 5 MINUTES, make SURE blablabla

:next2
net send USER2 EOD in 5 MINUTES, make SURE blablabla
if %errorlevel% EQU 2 goto next3
net send USER2 EOD in 5 MINUTES, make SURE blablabla
net send USER2 EOD in 5 MINUTES, make SURE blablabla

......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top