windows bat 文件:撤消 NET USE
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7077325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
windows bat file: undo NET USE
提问by clamp
In a batch-file I use the following syntax to map a network drive:
在批处理文件中,我使用以下语法来映射网络驱动器:
NET USE N: \\someserver\somedirectory.
NET 使用 N:\\someserver\somedirectory。
While this works fine, it also gives an error if the letter n is already used. Is it possible to suppress this error message?
虽然这工作正常,但如果字母 n 已被使用,它也会出错。是否可以抑制此错误消息?
Also, is there a way to unmap a network drive?
另外,有没有办法取消网络驱动器的映射?
I imagine something like:
我想像这样:
NET UNUSE N:
净未使用 N:
回答by Alex K.
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
回答by Scott Weinstein
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.
您将$?
在 PowerShell 和%ERRORLEVEL%
Batch 中获得不同的返回结果。
If mapped $? will be True
and %ERRORLEVEL%
will be 0
如果映射 $? 将会True
并且%ERRORLEVEL%
将会是 0
To unmap, just do
要取消映射,只需执行
net use N: /DELETE
回答by Calle
The easiest is: IF NOT EXIST N:. NET USE N: \someserver\somedirectory
最简单的是:IF NOT EXIST N:。网络使用 N:\someserver\somedirectory