windows bat file: undo NET USE
In a batch-file I use the following syntax to map a network drive:
NET USE N: \\someserver\somedirectory.
While this works f开发者_开发问答ine, it also gives an error if the letter n is already used. Is it possible to suppress this error message?
Also, is there a way to unmap a network drive?
I imagine something like:
NET UNUSE N:
After
NET USE N: \\somserver\somedirectory
to remove simply:
NET USE N: /DELETE
To test for an existing mapping you can;
IF NOT EXIST N:\. GOTO BLABLA
You can detect if a drive is in use by running
net use N:
you'll get different return results $?
in PowerShell and %ERRORLEVEL%
in Batch.
If mapped $? will be True
and %ERRORLEVEL%
will be 0
To unmap, just do
net use N: /DELETE
The easiest is: IF NOT EXIST N:. NET USE N: \someserver\somedirectory
精彩评论