I have not worked with DOS much as there were always shell scripting in Unix which were more powerful. First time I am working on Windows and don’t know much about the DOS/Batch script.
I was trying to write a small script to restart the remote machine.
While making script sophisticate, I learned about the environment var %ERRORLEVEL%, which is kind of return code from the last ran command.
In Unix if command run but not produce the desire result or some error msg, error code is not zero.
As I am trying remote shutdown and providing host which does not exists in the network. It says that “Network path not found” but %ERRORLEVEL% is still zero. Which is whole point to asking this question.
Do I need to capture something other then %ERRORLEVEL%, as Zero is designated to ran successful command and it is not changing the %ERRORLEVEL% when throwing “Network path not found” what should I capture to get this right ?
shutdown command I am using:
shutdown -r -f -t %DELAYOF% -m \\%COMPNAME% -c %COMMENT%
When I give invalid value gives to %COMPNAME%, it prompt says “network path not found” but %EERORLEVEL% is not being changed.
The answer to your problem -the error level is that %compname% is not an environmental variable, however %computername% is.
Try this: (not tested)
If this isn’t what you’re looking for can you please post your script so that we can take a look at it, at least the parts that are relavant to this snippet.
As for the %ERRORLEVEL% try to put this in front of your command
The
verify >nulwill keep your errorlevel blank so that you don’t capture it from somewhere else.