Exit with errorlevel from windows batch
<p>In my batch file I have a function where use this command to connect to a remote host:</p>

<pre><code>net use %alias%: \\%host%\%root%$ %usrPwd% /USER:%usrName% &gt;&gt; %logfile% 2&gt;&amp;1 || ( call :exitIfError ERROR)
</code></pre>

<p>I created this function:</p>

<pre><code>:exitIfError
setlocal
(set txt=%~1)
if not ERRORLEVEL 0 ( echo %txt% &amp;&amp; exit  /B %errorlevel%)
endlocal
goto :eof
</code></pre>

<p>If I enter an incorrect password is generating the error, but doesn't finish with error and the value of %errolevel% is 0 
instead of 2. Suggestions?</p>