Vbscript / Files And Folders / Create Remote File Share
This script function creates a new folder and shares the folder with default permissions of everyone with full access. The script works for local and remote file shares.
strLocalFolder = "C:\Public" strComputer = "." strUNCFolder = "\" & strComputer & "\" & Replace(strLocalFolder,"C:","C$")
strShare = "Pubs" strDesc = "PublicShare"
createShare(strComputer, strLocalFolder, strUNCFolder, strShare, strDesc)
Function createShare(strComputer, strFolder, strShare, strDesc)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strUNCFolder) Then objFSO.CreateFolder(strUNCFolder) End If
Set Services = GetObject("WINMGMTS:{impersonationLevel=impersonate,(Security)}!\" & strComputer & "\ROOT\CIMV2") Set Share = Services.Get("Win32_Share") Set InParam = Share.Methods_("Create").InParameters.SpawnInstance_() InParam.Properties_.Item("Description") = strDesc InParam.Properties_.Item("Name") = strShare InParam.Properties_.Item("Path") = strLocalFolder InParam.Properties_.Item("Type") = 0 Set noth = Share.ExecMethod_("Create", InParam)
End Function
Please note that a disclaimer applies to any code on this page.
|