1. Manipulating Shares with net share
You can create shares from the command prompt with the net share command. The basic syntax is
net share sharename = drive:path
The following table describes some common uses with the net share command.
net share Commands | Comments |
---|
View shares.
| Shows a listing of all shares on the local system. |
Create a share.
c:\>net share data=c:\data
| Creates a share named data from the folder named c:\data. The Everyone group is granted Read permission by default.
Note
This is another one of those commands that is particular about the equal
sign (=). There shouldn’t be any spaces before or after the equal sign.
|
Delete a share.
/delete
c:\>net share data /delete
| The /delete switch deletes the named share. In this example, the share named data created in the previous step is deleted. |
Create a share with specified permissions.
/grant: user, [read | change |
full ]
c:\>net share data=c:\data
/grant:darril,full
c:\>net share data=c:\data
/grant:"authenticated users",full
| You can modify the default permissions by using the /grant
switch and specifying a user and the desired share permission. You can
specify a user or a group. If the user or group name includes a space,
it must be enclosed in quotes.
Note
Only the specified user or group is granted permissions. In other words,
the default of Everyone being granted Read permission is not used.
|
2. Mapping Drives with net use
There might be times when you’ll want to manipulate
or access files on a remote share. You can use the Universal Naming
Convention (UNC) of \\servername\sharename. However, some commands don’t
recognize the UNC path and need a drive letter, and sometimes it’s just
easier to use a drive letter instead of a full UNC path. You can use
the net use command to map drive letters to UNC paths. The basic syntax is
net use x: \\serverName\shareName
You can use any drive letter that is not in use on
the system, but if the drive letter is in use, the command will fail.
Additionally, the UNC path must be reachable or you’ll get an error.
net use Command | Description |
---|
| You can view all currently mapped drives with this command. |
c:\>net use z: \\fs1\public
| This maps the driver letter z: to a share named public on a remote host named fs1. |
/delete
c:\>net use z: /delete
| The /delete switch deletes the mapped drive and frees up the mapped drive letter. |
/persistent
c:\>net use /persistent: No
c:\>net use /persistent: Yes
| The /persistent switch is used by itself and specifies whether the mapped drives are remembered at the next logon. When set to no, the net use command includes the following line: “New connections will not be remembered.” This is the default.
When set to Yes, the net use command includes the following line: “New connections will be remembered.” Mapped drives will survive reboots. |
Tip
If mapping a drive from a script that you want to
survive reboots, it’s best to enable persistent connections, map the
drive, and then turn off persistent connections.