Is there a way to read the line of code that raised the errorlevel from within a batch file after its execution? (I'm afraid there isn't).
For example the command net use H: \\MyComputer\sharename02
would result in
System error 85 has occurred. The local device name is already in use.
In this case drive H: is not available and the errorlevel is no longer 0.
My aim is to fetch that command to modify it, somewhat like so:
@echo off
set _counter=0
net use F: \\MyComputer\sharename01 /persistent:No
IF %ERRORLEVEL% NEQ 0 goto manip
_counter=_counter+1
:next2
net use H: \\MyComputer\sharename02 /persistent:No
IF %ERRORLEVEL% NEQ 0 goto manip
_counter=_counter+1
:next3
net use I: \\MyComputer\sharename03 /persistent:No
IF %ERRORLEVEL% NEQ 0 goto manip
_counter=_counter+1
IF %ERRORLEVEL% EQU 0 goto end
:manip
(do something with...
_variable="\\MyComputer\sharenameXY"
...)
_counter=_counter+1
if _counter==3 (goto end)
else (goto next%_counter%)
:end
The section :manip
would work with the command net use H: \\MyComputer\sharename02
that got stored in _variable
.
I am aware that this kind of problem isn't really suited for Batch processing and would probably be easier solved using VBscript instead of batch.
Hope there is a solution otherwise I would need to rewrite all that I already have into VBscript or Powershell.