0
votes

I've found some vbscript examples on how to enable file sharing and share a folder, however they leave the "Public folder sharing" off so that you have to be logged in rather than just allowing anyone with network access to read/write to public folders.

For all my googling, I can't seem to find out how to automate that last piece. Vbscript or anything that can be run via command line would be my preferred method of doing this, but really I'm open to hearing about any solution that would automate this.

EDIT:

In case it's relevant, I should point out that I'm going to be running this locally with admin privileges on non-domain computers.

EDIT2:

I've tried the solutions listed below, however the option I need to change affects the ability to connect to a computer to see the list of shares; it's not specific to a particular share.

1

1 Answers

0
votes

The simplest way would be shelling out:

Set sh = CreateObject("WScript.Shell")
sh.Run "net share sharename=C:\some\folder /grant:Everyone,FULL", 0, True

Doing it entirely in VBScript is possible, but requires significantly more code. A sample script for this has been published here, which could be simplified for your particular requirements like this:

path      = "C:\some\folder"
sharename = "name"
comment   = "foo"

Set wmi = GetObject("winmgmts://./root/cimv2")

Set trustee = wmi.Get("Win32_Trustee").SpawnInstance_()
trustee.Domain = Null
trustee.Name   = "Everyone"
trustee.SID    = Array(1,1,0,0,0,0,0,1,0,0,0,0) 'SID S-1-1-0 (binary)

Set ace = wmi.Get("Win32_Ace").SpawnInstance_()
ace.AccessMask = 2032127  'full access
ace.AceFlags   = 3        'object inheritance + container inheritance
ace.AceType    = 0        'allow access
ace.Trustee    = trustee

Set sd = wmi.Get("Win32_SecurityDescriptor").SpawnInstance_()
sd.DACL = Array(ace)

Set share = wmi.Get("Win32_Share")
rc = share.Create(path, sharename, 0, 10, comment, "", sd)

If rc = 0 Then
  WScript.Echo "Folder " & path & " has been shared as " & sharename & "."
Else
  WScript.Echo "Error sharing folder " & path & ": " & rc
End If