Thursday, July 31, 2008

Scripts: Create Share

The below code will create a new share on the local system.

On Error Resume Next
Const PType = 0 'value 0 specifies diskdrive
StrPath = "e:\share"
StrShareName = "share"
StrDescription = "This is a File Share"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set objNewShare = objWMIService.Get("Win32_Share")

errReturn = objNewShare.Create _
(StrPath, StrShareName, PType, , StrDescr)
wscript.echo errReturn


No comments: