creating shares remotely

Sep 06, 2011 16:53

(shamelessly stolen from http://www.petri.co.il/forums/showthread.php?t=41311, who apparently shamelessly stole it from the Scripting Guy site anyway)

Const FILE_SHARE = 0
Const MAXIMUM_CONNECTIONS = 25

strComputer = "atl-ws-01"
Set objWMIService = GetObject _
("winmgmts:\\" & strComputer & "\root\cimv2")

Set objNewShare = objWMIService.Get("Win32_Share")

errReturn = objNewShare.Create _
("C:\Public", "PublicShare", FILE_SHARE, _
MAXIMUM_CONNECTIONS, "Public share for Fabrikam employees.")

strComputer = "atl-ws-01"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colShares = objWMIService.ExecQuery _
("Select * from Win32_Share Where Name = 'PublicShare'")
For Each objShare in colShares
objShare.Delete
Next
wscript.Sleep 3000
WScript.Echo "Done"
WScript.Quit

can also create using wmic:
@echo on
wmic /node:Computer name /user:"domain\username" /password:user password share call create "", "Share Description", "Maximum Connections", "Share Name", "", "Local Path", 0
wmic exit

reference

Previous post Next post
Up