Windows 7 sharing folder from command line, selecting users and triggering the "Apply" of changes

Posted by clintp on Server Fault See other posts from Server Fault or by clintp
Published on 2011-01-16T22:49:17Z Indexed on 2011/01/16 22:54 UTC
Read the original article Hit count: 240

I have a drive that doesn't get mounted until after I log in. (A Truecrypt thumbdrive device, and no, I'm not making it a "System Favorite" to get around this.) I'd like to construct a batch file to share it once I've gotten it mounted because the sharing info doesn't seem to stick through a reboot.

From the GUI, I'd go into the folder Properties->Sharing. And then in Advanced Sharing I'd pick the name to share it as. And then under the "Share..." button I'd pick the users and the permissions I want to grant them. After "Apply" there's a pause -- I'm not sure what's happening here, but the dialog says "Sharing Items..." -- and then everything is okay.

From the command line, I've done:

net share MyFolder=F:\MyFolder
cacls F:\MyFolder /G FirstUser:F
cacls F:\MyFolder /G OtherUser:F

And this almost works. I can see the share on the network then, but nobody has permissions to do anything. If I go into the GUI and change anything (and I can see my command-line changes in there already) and press "Apply" I get the:

"Sharing Items.... 
 This may take a few minutes"

Dialog... and then Voila! It works. I get the "Your folder is shared" dialog with the command-line changes I made, along with the GUI change that I made to trigger the "Sharing Items..." dialog. Everything's peachy.

Is a service being restarted? Which one?

What's triggering the sharing to take effect? And -- more importantly -- how do I do it from the command line?

© Server Fault or respective owner

Related posts about permissions

Related posts about command-line