Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have the following situation:

  • I need to share a folder in the root of drive C: on a Windows 7 machine.
  • The share should provide read/write access for anybody on other machines on the local network.
  • The Windows 7 machine is not part of a domain.
  • I need to establish the share from code (command line tools).
  • If at all possible, the code should work on any localized Windows 7 installation

To my understanding there are two types of permissions I have to deal with:

  • Share permissions and
  • NTFS permissions.

Both need to allow read/write access for the final solution to work.

Now, let's assume that the folder to be shared is named C:\SharedFolder. With elevated privileges I use command line tools to create the folder and then provide the share:

  1. MD C:\SharedFolder

  2. NET SHARE ShareName=C:\SharedFolder /GRANT:Everyone,Full

  3. icacls c:\SharedFolder /grant:r *S-1-1-0:F

Step 1 creates the folder, step 2 creates the share with the right share-permissions, and step 3 adds the needed NTFS permissions, right? (note, that "S-1-1-0" is just the SID corresponding to "Everyone").

With these three steps I end up with the desired share, but when I connect to the share from another machine I only have read-only access! Why is that?

If I right-click on the shared folder on the Windows 7 machine I get this:

Folder Properties Window

Note that the read-only check box is somewhat marked!

I can easily solve the situation by clicking away the read-only mark (followed by click on "OK" or "Apply"), but how can I do this from code? And why is it at all necessary?

Also note, that the NET SHARE command uses the term "Everyone" in its /grant switch. This is problematic, because in a German Windows 7 you should write "Jeder" instead of "Everyone", and in a Danish Windows the proper word would be "Alle".

This language problem is not an issue in the icacls command, because here I can use the corresponding SID instead (as shown). But how can I make the NET SHARE command work for any language too?

share|improve this question

migrated from stackoverflow.com Apr 18 '13 at 13:53

This question came from our site for professional and enthusiast programmers.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.