Search Tools Links Login

Managing Shares at the Command Line


Manage your shares from the command prompt with built-in-to-Windows tools, and leave the GUI to the noobs. There are many ways to manage shares using the graphical interface of Windows Explorer. There are some of us die-hard command prompt junkies that prefer working at the text level, however. Also, in some cases, you may only have a command prompt for your admin duties. Windows Server 2008 includes a variation of installation called Server Core. Server Core is a significantly scaled-back installation where no Windows Explorer shell is installed. All configuration and maintenance is done entirely through command line interface windows, or by connecting to the machine remotely using Microsoft Management Console. However, Notepad and some control panel applets, such as Regional Settings, are available. So onward, to share management. Net Share Command-line Syntax The first step in learning to use the net share command is to gain a basic understanding of the command line syntax of the tool. Let's take a look at the help file for NET SHARE, which we will be using to manage our shares.

NET SHARE
sharename
          sharename=drive:path [/GRANT:user,[READ | CHANGE | FULL]]
                               [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | None ]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | None]
          {sharename | devicename | drive:path} /DELETE
          sharename \\computername /DELETE

As you can see by this list, many of the tasks you would normally use the GUI for, you can also perform with the command line tool. In this article, we'll just cover some of the highlights:

Note that to perform any tasks other than viewing the current shares, the command-prompt must be running with administrator privileges. This can be achieved by right clicking on the Command Prompt in the Start menu and selecting Run as administrator. Getting Share Information using NET SHARE To obtain information about currently configured shares on a Windows Server 2008 system simply execute the net share command will no command-line options:

C:\>net share

Share name   Resource                        Remark

-------------------------------------------------------------------------------
ADMIN$       C:\Windows                      Remote Admin
C$           C:\                             Default share
print$       C:\Windows\system32\spool\drivers
                                             Printer Drivers
K$           K:\                             Default share
IPC$                                         Remote IPC
NetworkBackups
             C:\NetworkBackups
TestFolder   c:\test
Users        C:\Users
The command completed successfully.

Creating a Share using NET SHARE Perhaps the most common requirement when working with shared files and folders is to create a new share. The most basic of commands simply creates the share and assigns a share name. For example: C:\>net share TestFolder=c:\test TestFolder was shared successfully. In the above example, the folder located at c:\test has been shared using the share name TestFolder. By default, Windows will assign read permission to Everyone when a share is created without specifying any permissions. In order to grant specific permissions to individual users or groups, the /GRANT option must be used when creating the share to specify the share permissions to be assigned. For example, the following command creates the TestFolder share assigning full permission to user George: C:\>net share TestFolder=c:\test /GRANT:George,FULL TestFolder was shared successfully. If permissions need to be granted to multiple users or groups, the /GRANT option may be used multiple times in a single net share command. In the following example, full share permissions are granted to user George while Steve is only assigned read permission: C:\>net share TestFolder=c:\test /GRANT:George,FULL /GRANT:Steve,READ TestFolder was shared successfully. To create a share with comments use the /REMARK argument following by the comment text: C:\>net share TestFolder=c:\test /REMARK:"The Test Folder" TestFolder was shared successfully. Using Net Share to Delete a Share from a Local Server To remove a share from a local server using the net share command together the share name of the share to be deleted together with the /DELETE option. For example: C:\>net share TestFolder /DELETEM TestFolder was deleted successfully. Using Net Share to Delete a Share from a Remote Server The net share command may also be used to delete a share from a remote server. In order to achieve this, the name of the remote computer on which the share resides must be specified before the /DELETE option prefixed with \\. In the following command-line, the share named TestFolder is removed from a remote server named winserver-2: C:\>net share TestFolder \\MyServer /DELETE TestFolder was deleted successfully. Once executed, provided you have administrative permissions on the remote computer, the above command will delete the share named TestFolder from the remote server named MyServer such that it is no longer available for remote shared access.

About this post

Posted: 2010-02-27
By: dwirch
Viewed: 13,720 times

Categories

Tip

Tutorials

Windows

Windows Server

Attachments

No attachments for this post


Loading Comments ...

Comments

AnonymousCoward posted this comment on 2015-08-08:

Ok, everything worked fine, but when I try to grant full acces to a specific user in my local network it gave the 1332 error. 
i tried this: "net share toshi=e:\sharedfolder /grant:gonzalo-unzueta\gonzalo,full" where gonzalo-unzueta is another computer in local network and gonzalo a user of that computer. 

dwirch posted this comment on 2015-08-08:

If the computers are in workgroup mode, I believe you can only use local accounts; you won't be able to reference accounts maintained on other computers in the network. 

If you want to reference accounts that are not local to the machine share is on, you need to set up a domain, and utilize domain accounts.

gonchi_Bolivia posted this comment on 2015-08-13:

Oh hehe, didn't know that it would appear my name as AnonymousCoward =P 

But thank you for the answere. You are right my computers are in workgroup mode, was kind of annoying not knowing why I couldn't do that, now that I know, I'll set up a Domain. 

You must be logged in to make a comment.