11

This is sort of a two-pronged question.

I am developing an application that will need to be able to create network shares in Windows Server 2003 via the command line. So, firstly, how do I create shares in Windows via the command line? I tried researching it, and all I was able to find is that I should be using net, but other than that, there isn't much documentation.

Also, in this share there will be a few directories with the names of users on the domain, and I would like for the directories to not be readable or writable by anyone else. For example, say I have two directories: jsmith and jdoe. I would like the user jsmith to write and read from the directory jsmith, but not the directory called jdoe, and vice versa.

2 Answers 2

5

This should be the information that you are looking for:

::Create a drive letter map to an existing network share
net use z: \\servername\share password /USER:domain\username /PERSISTENT:YES

:: grant user 'jsmith' full control access to the jsmith directory
cacls z:\jsmith /T /E /G jsmith:f

You can also remove permissions, or edit permissions on the directory using cacls.exe. My recommendation would be to read up on cacls.exe

Cacls

http://technet.microsoft.com/en-us/library/bb490872.aspx

or just "cacls /?" from the command line should work as well.

4
  • 1
    PERSIST_E_NT ;)
    – michabbb
    Apr 10, 2018 at 16:34
  • What does the option "/PERSISTENT:YES" ? Nov 20, 2019 at 13:13
  • From Microsoft (docs.microsoft.com/en-us/previous-versions/windows/it-pro/…): Controls the use of persistent network connections. The default is the setting used last. Deviceless connections are not persistent. Yes saves all connections as they are made, and restores them at next logon. No does not save the connection being made or subsequent connections. Existing connections are restored at the next logon. Use /delete to remove persistent connections.
    – matrixx333
    Nov 21, 2019 at 14:36
  • Follow up for anyone using Windows 10: "cacls.exe" has been deprecated in favor of "icacls.exe" which does much the same thing. Jan 26, 2021 at 22:32
11

The command you're looking for is net share. The /? help on the command is pretty straightforward, but here is an example:

net share MyShareName="C:\My Local Path\SomeFolder" /GRANT:Everyone,FULL

As far as security goes, from what I've read, the best-practice is to do as above, grant the Everyone group full control on the share, and then manage the permissions on the files and folders themselves. This is because the share permissions are a restriction filter over top of the actual file and folder permissions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .