Windows operating systems provides some mechanism to share the resources between different systems. One of the most known and popular tool to manage these resources is net
command whit related sub command. In this tutorial we will look how to create, mount, remove and manage network shares with net use
and net share
command.
Windows操作系统提供了一种在不同系统之间共享资源的机制。 与这些命令相关的net
命令是管理这些资源的最广为人知的工具之一。 在本教程中,我们将研究如何使用net use
和net share
命令创建,安装,删除和管理网络net share
。
句法 (Syntax)
We will use following syntax for net use
.
我们将使用以下语法进行net use
。
net use [option]
帮帮我 (Help)
Help about net use command can be get with the following command.
可以使用以下命令获取有关net use命令的帮助。
$ net use /?
建立分享(Create Share)
We will create a share which maps to the C:\cygwin64
folder. We will also set the network share name as myshare
with the following command. We will provide the share name and the path like below.
我们将创建一个映射到C:\cygwin64
文件夹的共享。 我们还将使用以下命令将网络共享名称设置为myshare
。 我们将提供共享名称和如下所示的路径。
$ net share "myshare=c:\cygwin64"
We have successfully created the share named myshare
. If we have do not have permission for given mapped shared directory we will get error and the share will not created.
我们已经成功创建了名为myshare
的共享。 如果我们没有给定映射共享目录的权限,则会收到错误消息,并且不会创建共享。
列出股份 (List Shares)
Existing shares can be listed with net share
command without providing any parameter. This will list current host network shares.
可以使用net share
命令列出现有net share
而无需提供任何参数。 这将列出当前的主机网络共享。
$ net share
As we see from screenshot there are a lot of shares. Shares like C$, ADMIN$
are created by default. If we do not need them we should remove them. Listing shares provides following information
正如我们从屏幕截图中看到的,有很多份额。 默认情况下会创建C$, ADMIN$
类的共享。 如果我们不需要它们,则应将其删除。 上市股票提供以下信息
Share name
is the name used to mount this share in the client sideShare name
是用于在客户端安装此共享的名称Resource
is the path the share will be mappedResource
是共享将被映射的路径Remark
is comments and notes about this share which is set while share creation.Remark
是在创建共享时设置的有关此共享的注释和注释。
挂载共享 (Mount Share)
We have created and listed shares in previous mount shares are easy as creating them. We will use net use
command to mount a windows share from command line. We will mount share named myshare
located at 192.168.122.167 to our drive z:
.
我们已经在以前的装载共享中创建并列出共享,就像创建它们一样容易。 我们将使用net use
命令从命令行挂载Windows共享。 我们将名为myshare
共享安装在驱动器z:
共享位于192.168.122.167。
$ net use z: \\192.168.122.167\myshare
We have successfully mounted the share. While mounting user credentials should be provided. but in this example the share was created with the same user who mounts the share. So we have all ready have permission access to the share.
我们已经成功安装了共享。 挂载时,应提供用户凭证。 但是在此示例中,共享是由安装共享的同一用户创建的。 因此,我们都准备好了对共享的访问权限。
列出挂载的份额 (List Mounted Shares)
We have mounted the remote file share in the previous example. We can list all ready mounted shares simply using net use
command like below.
在上一个示例中,我们已经安装了远程文件共享。 我们可以简单地使用net use
命令列出所有已安装的共享,如下所示。
$ net use
Listing shares will provide information like below.
上市股票将提供如下信息。
Status
shows current situation like connected or not connectedStatus
显示当前状态,例如已连接或未连接Local
shown the local mount pointLocal
显示本地安装点Remote
shows remote file share full path including the host name/IP address and the pathRemote
显示远程文件共享的完整路径,包括主机名/ IP地址和路径Network
shows network used to access share.Network
显示用于访问共享的网络。
卸载份额 (Unmount Share)
We can unmount a share similar like mounting it. We will provide /delete
option to the mount command like below. In the example we will unmount the remote share name \\192.168.122.167\myshare
from our local system.
我们可以卸载类似安装的共享。 我们将为mount命令提供/delete
选项,如下所示。 在示例中,我们将从本地系统卸载远程共享名\\192.168.122.167\myshare
。
$ net use z: \\192.168.122.167\myshare /delete
删除或删除具有共享名的共享 (Delete or Remove Share With Share Name)
We can stop sharing previously shared resource with the /delete
parameter and the share name. In this example we will stop sharing myshare
.
我们可以停止使用/delete
参数和共享名共享以前共享的资源。 在此示例中,我们将停止共享myshare
。
$ net share myshare /delete
删除或删除具有实际位置的共享(Delete or Remove Share With Physical Location)
Alternative way to remove a share is providing the physical location of the shares. This will delete related share and share name. In this example we will provide physical location as c:\cygwin64
to remove related share.
删除共享的另一种方法是提供共享的物理位置。 这将删除相关的共享和共享名称。 在此示例中,我们将提供物理位置为c:\cygwin64
以删除相关共享。
$ net share c:\cygwin64 /delete
从远程计算机删除或删除共享 (Delete or Remove Share From Remote Computer)
In previous example we have removed existing share from local computer. We can also remove remote systems share by specifying remote system IP address or host name. In this example we will remove share from 192.168.122.66
with the following command.
在前面的示例中,我们从本地计算机上删除了现有共享。 我们还可以通过指定远程系统IP地址或主机名来删除远程系统共享。 在此示例中,我们将使用以下命令从192.168.122.66
删除共享。
$ net share myshare \\192.168.122.66 /delete
设置共享访问权限 (Set Permission For Share Access)
While creating network shares the access permission is important factor for security reasons. We must set which users accounts can access to the share with which access rights. This can be set with /GRANT
option and specifying user and rights. Syntax of grant options is like below.
创建网络共享时,出于安全原因,访问许可是重要因素。 我们必须设置哪些用户帐户可以访问具有哪些访问权限的共享。 可以使用/GRANT
选项进行设置,并指定用户和权限。 授予选项的语法如下。
/GRANT:username,right
In this example we will give user account john
full access which means READ
, WRITE
and EXECUTE
permissions for the given share.
在此示例中,我们将为用户帐户john
授予完全访问权限,这意味着对给定共享具有READ
, WRITE
和EXECUTE
权限。
$ net share myshare myshare /GRANT:john,FULL
翻译自: https://www.poftut.com/how-to-add-remove-and-manage-windows-shares-network-drives-from-command-line/