I didn't know if I should start this topic under "Programming" but it seems to be the only place to put it.
I want to run a batch file that will automatically map a network drive before it continues the script. The problem I have is that if for some reason the drive is already mapped, or the batch file has been run twice in one session, the "net use" command returns an error. The script still works in the end, but I would like to bypass the "net use" command altogether if the drive is already mapped.
I've been digging through the net trying to find anything that can help me out, but to no avail. The closest thing I can find is just typing "net use" can tell you if the drive is already mapped or not, but I can't take any one piece of that result and use it in my script.
Does anyone have any suggestions? My purpose here is to write an IF statement that determines:
IF drive X: is already mapped, then skip net use command and proceed with the remainder of the script.
ELSE, run net use command and proceed with the remainder of the script.
I figured ERRORLEVEL could come in handy, but that only works after I get the error that I'm trying to avoid in the first place.
Question
Xtreme $niper
I didn't know if I should start this topic under "Programming" but it seems to be the only place to put it.
I want to run a batch file that will automatically map a network drive before it continues the script. The problem I have is that if for some reason the drive is already mapped, or the batch file has been run twice in one session, the "net use" command returns an error. The script still works in the end, but I would like to bypass the "net use" command altogether if the drive is already mapped.
I've been digging through the net trying to find anything that can help me out, but to no avail. The closest thing I can find is just typing "net use" can tell you if the drive is already mapped or not, but I can't take any one piece of that result and use it in my script.
Does anyone have any suggestions? My purpose here is to write an IF statement that determines:
IF drive X: is already mapped, then skip net use command and proceed with the remainder of the script.
ELSE, run net use command and proceed with the remainder of the script.
I figured ERRORLEVEL could come in handy, but that only works after I get the error that I'm trying to avoid in the first place.
Thanks!
Link to comment
Share on other sites
19 answers to this question
Recommended Posts