Create user shares

Various VB Scripts
Post Reply
thockman
Site Admin
Posts: 104
Joined: Thu Dec 15, 2005 5:51 pm
Location: Kansas City
Contact:

Create user shares

Post by thockman » Thu Dec 15, 2005 10:52 pm

I wrote this script to be able to recreate the users shares under the Home directory while migrating. It would also be good to recreate the shares quickly in the event of issue.

Code: Select all

'Created BY: Troy Hockman
'Created Date: 2003/05/19
'Description: Script to create user shares for migration
 
On Error Resume Next
Dim oFS, sSite, sDomain, sFilePath, sBaseDir, sDept
 
sComputer = "."
'Browse for folder
Const WINDOW_HANDLE = 0
Const NO_OPTIONS = 0
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, "Select a folder:", NO_OPTIONS, "C:\Scripts")        
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
objPath = Replace(objPath, "\", "\\")
strComputer = "."
Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery ("Select * from Win32_Directory where name = '" & objPath & "'")
For Each objFile in colFiles
    sFolder = objfile.Name
Next
 
'Create display window in IE and display what I am doing
Set objExplorer = WScript.CreateObject("InternetExplorer.Application")
objExplorer.Navigate "about:blank"    
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 700
objExplorer.Height = 200  
objExplorer.Left = 400
objExplorer.Top = 500
Do While (objExplorer.Busy)
    Wscript.Sleep 300
Loop     
objExplorer.Visible = 1              
objExplorer.Document.Body.InnerHTML = "Getting directories from " & sFolder & ".  Please wait.."
Wscript.Sleep 2000
 
'Create file object
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(sFolder)
Set colSubfolders = objFolder.Subfolders
 
objExplorer.Document.Body.InnerHTML = "Creating Shares..."
Wscript.Sleep 1000
 
 
Set oSvr = GetObject("WinNT://" & sComputer & ",Computer")
Set oShr = GetObject(oSvr.ADsPath & "/" & "LanmanServer")
 
For Each objSubfolder in colSubfolders
    sFilePath = sFolder & "\" & objSubfolder.Name
    sFolderName = objSubfolder.Name
    'Create share
    objExplorer.Document.Body.InnerHTML = "Creating...<br>Share: " & sFilePath & "$"
    Set oFileShare = oShr.Create("FileShare", sFolderName & "$")
    oFileShare.Path = sFilePath
    oFileShare.MaxUserCount = -1
    oFileShare.SetInfo
Next
objExplorer.Document.Body.InnerHTML = "Complete..."
wscript.quit

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest