Reputation: 21
I need to have a batch file with multiple drive mapping statements like this:
@echo off
net use Q: \\serve\share
When the drive is already connected, I get system error 85. How can I monitor for the 85 error and take my own action (like a cheap goto already_connected)? If it's any error other than an 85, I want to see the message displayed (or grab it from a variable and display it... whatever).
I've tried some samples I found, but I can't seem to suppress the system error display and I can't figure out how to trap specifically for the 85 error. If I could get a sample of how to do the error suppression, trapping, etc I can probably craft the rest of the code.
Thanks,
Upvotes: 2
Views: 918
Reputation: 70923
Instead of checking for error after map, check for map before error
edited to correct an error in existing map search
call :doMap q: "\\server\share"
....
:doMap drive share
rem search for drive map in server
net use | find /i "%~1" | find /i "%~2" > nul
if errorlevel 1 (
rem if not found, test if drive letter is mapped
rem and remove map if needed
net use | find /i "%~1" > nul && net use "%~1" /delete >nul
rem map drive to server share
net use %~1 "%~2" > nul
)
goto :eof
Upvotes: 2
Reputation: 57252
net use Q: \\serve\share 2>&1 | find "85" &&(
echo error 85
)
??
Upvotes: 1