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 are 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:
- View current shares
- Create a share
- Manager Share Permissions
- Delete a share
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 with 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.