Code Script .co.uk

Home | Scripts | Tutorials | Disclaimer | Sitemap | Contact

   Create Remote File Share
 

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.
 
   Actions
  Go Back
  Bookmark
  Print Page


   Menu
 
- Links
- Reference
- Script Editors
- Tutorials
- Vbscript
     - Active Directory
     - Exchange
     - Files And Folders
          - Auto Copy Files From Cdrom
          - Backup My Documents
          - Cleanup Filenames
          - Create Remote File Share
          - File Properties
          - File Server Report
          - File Type Report Scan
          - Find And Replace Filename Text
          - Find And Replace Text In Files
          - Folder Size Scanner
          - Rename Files Find And Remove Text
          - Rename Files Find And Replace Text
          - Replace Folder Ntfs Security Permissions
          - Simple File Report
          - Sort And Move Files To Folders
          - Windows File Locations
     - General
     - Ms Office
     - Operating System
     - Processes And Services
     - Text Processing
     - User Interaction
     - Web Servers