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.
We will use following syntax for
net use [option]
Help about net use command can be get with the following command.
$ net use /?
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.
$ 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.
Existing shares can be listed with
net share command without providing any parameter. This will list current host network shares.
$ 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
Share nameis the name used to mount this share in the client side
Resourceis the path the share will be mapped
Remarkis comments and notes about this share which is set while share creation.
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
$ 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
Listing shares will provide information like below.
Statusshows current situation like connected or not connected
Localshown the local mount point
Remoteshows remote file share full path including the host name/IP address and the path
Networkshows network used to access 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.
$ 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
$ 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.
$ 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.
$ 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.
In this example we will give user account
john full access which means
EXECUTE permissions for the given share.
$ net share myshare myshare /GRANT:john,FULL