Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Shared Folder Question

Status
Not open for further replies.

fpachon

MIS
Feb 9, 2006
22
US
Hi all,

I created this script which publishes a shared folder in AD, then creates the shared folder, then assigns the shared folder to a group. My question now is how do I go about setting permissions for this shared folder? I have seen some post regarding WMI and other ways of doing it but which is the easiest for a beginner.

Thanks.

Code:
'  Input File:  sharedlist.csv 
'
'  Parameters:  organizationalunit,sharename,description,group


Dim objFSO, objTextfile, ou_arr, s

Const ForReading = 1

Const FILE_SHARE = 0

Const AllowMaximum = True

Const ADS_PROPERTY_APPEND = 3 

strComputer = "."

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextfile = objFSO.OpenTextFile("shareslist.csv", ForReading)

Do while objTextfile.AtEndOfStream <> True

   s = objTextfile.Readline

   If instr(s, ",") Then
      
      ou_arr = split(s, ",")

      wscript.Echo "ou = " 		& ou_arr(0)
      wscript.Echo "sharename = "	& ou_arr(1)
      Wscript.Echo "description = "     & ou_arr(2)
      Wscript.Echo "group = "           & ou_arr(3)

      
' Publish Shared Folder in Active Directory


      Set objComputer = GetObject ("LDAP://OU=" & ou_arr(0) & ", DC=test")

      Set objShare = objComputer.Create("volume", "CN=" & ou_arr(1) )

      objShare.Put "uNCName", "\\2003srv\" & ou_arr(1)

      objShare.Put "Description", "" & ou_arr(2)

      objShare.SetInfo
      
      Wscript.Echo " Published in AD."
      WScript.Echo VbCrLf


'Make share

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

      Set objNewShare = objWMIService.Get("Win32_Share")

      errReturn = objNewShare.Create ("C:\Shares\" & ou_arr(1),"" & ou_arr(1), FILE_SHARE,_
        AllowMaximum, "Public share for the Health group.")

      Wscript.Echo errReturn

      Wscript.Echo "Share created."
 
      WScript.Echo VbCrLf

      Set objGroup = GetObject("LDAP://cn=" & ou_arr(3) & ",ou=" & ou_arr(0) & ",dc=test")

      objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array("cn=" & ou_arr(1) & ",ou=" & ou_arr(0) & ",dc=test")

      objGroup.SetInfo
   
      If Err <> 0 Then

        Wscript.echo Err.Number & " -- " & Err.Description
        Err.Clear

      End If     

   Else

   Wscript.Echo "End of file"

   End If

Loop

objTextFile.Close
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top