How To Add, Remove and Manage Windows Shares Network Drives From Command Line? – POFTUT

How To Add, Remove and Manage Windows Shares Network Drives From Command Line?


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.

Syntax

We will use following syntax for net use.

net use [option]

Help

Help about net use command can be get with the following command.

$ net use /?
net use Help
net use Help

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.

$ net share "myshare=c:\cygwin64"
net use - Create Share
net use – Create Share

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.

List Shares

Existing shares can be listed with net share command without providing any parameter. This will list current host network shares.

$ net share
List Shares with net use
List Shares with net use

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 name is the name used to mount this share in the client side
  • Resource is the path the share will be mapped
  •  Remark is comments  and notes about this share which is set while share creation.

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 z: \\192.168.122.167\myshare
Mount Share with net use
Mount Share with net use

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.

LEARN MORE  How To Use Net Use Command In Windows Command Line?

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
List Mounted Shares with net use
List Mounted Shares with net use

Listing shares will provide information like below.

  • Status shows current situation like connected or not connected
  • Local shown the local mount point
  • Remote shows remote file share full path including the host name/IP address and the path
  • Network shows network used to access share.

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.

$ 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 .

$ net share myshare /delete
Delete or Remove Share
Delete or Remove Share

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.

/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.

$ net share myshare myshare /GRANT:john,FULL

1 thought on “How To Add, Remove and Manage Windows Shares Network Drives From Command Line?”

Leave a Comment