开发者

windows bat file: undo NET USE

开发者 https://www.devze.com 2023-03-28 22:32 出处:网络
In a batch-file I use the following syntax to map a network drive: NET USE N: \\\\someserver\\somedirectory.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消