如何在Windows命令行中使用Net Use命令?

Windows operating systems provide the net use command in order to connect ,remove, configure connections to the shared resources like mapped drives, network resources and network printers. net use command is used from command line and provided operating systems Windows XP, Windows 7, Windows 8, windows 10 and Windows Servers from 2003 to 2019 .

Windows操作系统提供net use命令以连接,删除,配置与共享资源(如映射驱动器,网络资源和网络打印机)的连接。 net use命令是从命令行使用的,提供的操作系统是Windows XP,Windows 7,Windows 8,Windows 10和Windows Servers(2003年至2019年)。

句法 (Syntax)

net use command has following usage syntax. We will provide the drive name and the path we want to use.

net use命令具有以下用法语法。 我们将提供驱动器名称和我们要使用的路径。

net use DRIVE: PATH
  • `DRIVE:` is the name of the drive like `:G` `:Z` etc. used with local system.

    DRIVE:是与本地系统一起使用的驱动器的名称,例如:: G`:Z`等。
  • `PATH` is the remote resource we want to use which will provide the IP address or hostname with resource URI. Example \\192.168.1.20\test

    PATH是我们要使用的远程资源,它将为IP地址或主机名提供资源URI。 示例\\ 192.168.1.20 \ test

帮帮我 (Help)

We can get some help about net use command by using /? parameters like below.

我们可以通过使用/?获得有关net use命令的帮助/? 参数如下。

> net use /?
net use Help
net use Help
网络使用帮助

列出现有股份(List Currently Existing Shares)

We will start by listing currently existing, joined or mounted remote shares. We will just use net use command like below.

我们将从列出现有的,已加入的或已安装的远程共享开始。 我们将只使用如下的net use命令。

> net use
List Currently Existing Shares
List Currently Existing Shares
列出现有股份

加入或挂载远程文件共享(Join or Mount A Remote File Share)

We will start with a simple example by mounting a remote file share into our local system. We will mount file share named Backup which resides at 192.168.145.162

我们将从一个简单的示例开始,即将远程文件共享安装到本地系统中。 我们将挂载名为Backup文件共享,该文件共享位于192.168.145.162

> net use z: \\192.168.145.162\Backup
Join or Mount A Remote File Share
Join or Mount A Remote File Share
加入或挂载远程文件共享

与指定用户加入文件共享(Join File Share with Specified User)

In previous example we have mounted remote file share with the current user and privileges. In some cases we may need to mount with a different user than current session user. We can specify the user we want to use with /USER option. In this example we will use user Administrator .

在前面的示例中,我们使用当前用户和特权安装了远程文件共享。 在某些情况下,我们可能需要使用与当前会话用户不同的用户进行装载。 我们可以使用/USER选项指定要使用的/USER 。 在此示例中,我们将使用用户Administrator

> net use z: \\192.168.145.162\Backup /USER:Administrator
Join File Share with Specified User
Join File Share with Specified User
与指定用户加入文件共享

There will also also some information about the mount like Status, Connections, Resource type.

也将提供有关安装的一些信息,例如状态,连接,资源类型。

LEARN MORE  How To Add, Remove and Manage Windows Shares Network Drives From Command Line?
了解更多如何从命令行添加,删除和管理Windows共享网络驱动器?

OR we can also provide the user password explicitly. Keep in mind that providing password in clear text is a security problem. Password will be 123456Aa.

或者,我们也可以显式提供用户密码。 请记住,以明文形式提供密码是一个安全问题。 密码将为123456Aa.

> net use z: \\192.168.145.162\Backup /USER:Administrator  123456Aa.

永久加入文件共享 (Join File Share Persistently)

Mounting or joining remote file shares will have only effect current sessions. If session is closed or system is restarted or connection is lost the share will not mounted automatically. This is the default behavior. We can also join or mount a remote file share persistently with the /persistent:Yes .

挂载或加入远程文件共享只会影响当前会话。 如果会话关闭或系统重新启动或连接丢失,共享将不会自动安装。 这是默认行为。 我们还可以使用/persistent:Yes持久地加入或挂载远程文件共享。

> net use z: \\192.168.145.162\Backup /Persistent:Yes
Join File Share Persistently
Join File Share Persistently
永久加入文件共享

加入文件共享并指定驱动器号(Join File Share and Specify Drive Letter)

Up to now we have not specified a local drive letter to the mounted or joined remote share. The default behavior is providing a drive letter in a row manner. We can specify the drive letter like :W or :Z like below.

到目前为止,我们尚未为安装或加入的远程共享指定本地驱动器号。 默认行为是按行方式提供驱动器号。 我们可以指定驱动器号,例如:W:Z如下所示。

> net use :w \\192.168.145.162\Backup

永久保留所有将来的连接 (Make All Future Connections Persistent)

The default behavior of the net use command is making connections not persistent. If we want to make all future connection persistent without specifying persistent option explicitly we need to enable persistence globally like below.

net use命令的默认行为是使连接不是持久的。 如果我们想使所有未来的连接成为持久性,而没有明确指定持久性选项,则需要像下面这样全局启用持久性。

> net use /Persistent:Yes

加入打印机共享 (Join Printer Share)

Printers also a remote resource which can be used by multiple computers like file shares. We can use net use command in order to join a printer into local system. We just provide the printer IP address or host name.

打印机也是一种远程资源,可以供多台计算机使用,例如文件共享。 我们可以使用net use命令将打印机加入本地系统。 我们只提供打印机的IP地址或主机名。

> net use LPT1: \\192.168.1.10\prn

断开文件或打印机共享 (Disconnect From A File or Printer Share)

If we want to remove, delete or disconnect from all ready connected share we can use /delete option. We also need to specify the share letter we want to remove. In this example we will remote share named :z like below.

如果我们要删除,删除所有连接就绪的共享或与之断开连接,可以使用/delete选项。 我们还需要指定要删除的共享字母。 在此示例中,我们将如下所示远程共享名为:z

> net use :z /delete

断开并关闭所有共享 (Disconnect and Close All Shares)

We may need to removei close and disconnect all currently mounted shares. We will use *  with the /delete like below.

我们可能需要删除关闭并断开所有当前安装的共享的连接。 我们将*/delete一起使用,如下所示。

> net use * /delete
Disconnect and Close All Shares
Disconnect and Close All Shares
断开并关闭所有共享

There is a confirmation mechanism which will ask us that whether we want to continue removal of the remote shares.

有一个确认机制将询问我们是否要继续删除远程共享。

翻译自: https://www.poftut.com/how-to-use-net-use-command-in-windows-command-line/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值