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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating users shares for all users in a domain 2

Status
Not open for further replies.

rlee111

Technical User
Sep 10, 2001
27
0
0
GB
HI

I am working on a script to create shared folders for all users in a domain, here is the script

'script to create users shares for all users in a domain

Sub GetParentDir
ParentDir = "\\modrl\drives\home\"
If Not objFSO.FolderExists(ParentDir) Then
GetParentDir
End If
End Sub

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Set ShareServiceObj = GetObject("WinNT://" & objNetwork.ComputerName & "/LanManServer")

Domain = "rldom"
ParentDir = "C:\drives\home\"
GetParentDir
Drive = "L:"
Set DomainObj = GetObject("WinNT://" & Domain)
DomainObj.Filter = Array("User")

For Each UserObj in DomainObj
If Not objFSO.FolderExists(ParentDir & "\" & UserObj.Name) Then
objFSO.CreateFolder(ParentDir & "\" & UserObj.Name)
End If
ShareName = UserObj.Name
If Hidden Then
ShareName = ShareName & "$"
End If

On Error Resume Next
Set NewShare = ShareServiceObj.Create("fileshare", ShareName)
If Not Err Then
NewShare.Path = ParentDir & "\" & UserObj.Name
NewShare.MaxUserCount = 1 'Sets the limit for the number of user connections
NewShare.SetInfo
UserObj.HomeDirectory = "\\" & objNetwork.ComputerName & "\" & ShareName
UserObj.HomeDirDrive = Drive
UserObj.SetInfo
End If
Next

The script creates all the folders for all the users in my domain but doesnt share the folders.

Can someone point out where I am going wrong

Thanks
 
FileSystemObject does not have the ability to create shares, if you want to do this then you will have to use a different class/object (at least i think FSO doesnt)
 
>[tt]Sub GetParentDir
> ParentDir = "\\modrl\drives\home\"
> If Not objFSO.FolderExists(ParentDir) Then
> GetParentDir
> End If
>End Sub[/tt]
Why this structure? if "\\modrl\drives\home\" does not exist, you have an infinite recusion. You must have it exist, else you have been in trouble. But, you must change it. It is wrong.

In the main,
[tt]>ParentDir = "C:\drives\home\"
>GetParentDir[/tt]
The "c:\drives\home\" is meaningless. It will never make it as the sub immediately change it to a network url. Revise this part to reflect what you need.

 
this might be an old way of doing it but its all the info i have

Set objA = GetObject("WinNT://domain_here/server_here/LanmanServer)

Set objFileShare = objA.Create("fileshare", "nameofyourshare")
objFileShare.Path = "local path to folder?"
objFileShare.Description =
objFileShare.MaxUserCount = -1
FileShare.SetInfo
 
Ok I have left some legacy code in there which is obviously not needed thanks tsuji, removed some silly mistakes, the code below works ok now just one thing this line:

>NewShare.MaxUserCount = 1 'Sets the limit for the number of user connections

How do I set to maximum allowed?



Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
Set ShareServiceObj = GetObject("WinNT://" & objNetwork.ComputerName & "/LanManServer")

Domain = "rldom"
ParentDir = "C:\drives\home\"
Drive = "L:"
Set DomainObj = GetObject("WinNT://" & Domain)
DomainObj.Filter = Array("User")

For Each UserObj in DomainObj
If Not objFSO.FolderExists(ParentDir & UserObj.Name) Then
objFSO.CreateFolder(ParentDir & UserObj.Name)
End If

ShareName = UserObj.Name
On Error Resume Next
Set NewShare = ShareServiceObj.Create("fileshare", ShareName)
If Not Err Then
NewShare.Path = ParentDir & UserObj.Name
NewShare.MaxUserCount = 1 'Sets the limit for the number of user connections
NewShare.SetInfo
UserObj.HomeDirectory = "\\" & objNetwork.ComputerName & "\" & ShareName
UserObj.HomeDirDrive = Drive
UserObj.SetInfo
End If
Next
 
doc said:
MaxUserCount
[Visual Basic]
Access: Read-only [tt]([red]sic, maybe wrong[/red])[/tt]
DataType: Long

[C++]
HRESULT get_MaxUserCount
([out] LONG* plMaxUserCount);

The maximum number of users allowed to access the share at one time.
Set it to -1 for unlimited number of users to connect to it.
 
Ok I want to go further with this script, by default the folder shares I have created give everyone full permissions on the share I know it is not easy to do but can anyone tell me what I need to do to set folder share permissions for just the domain user who the share is for and domain admin, I have been looking at xcacls but can I use it in my script and where?

Thanks

Rob
 
xcalcs is the easiest way to do this, check out the command line options for it. /? or ? i think.
this should be all you need.
there are altenatives which can be seen as more work.
i have posted on such alternative before, do a search on adssecurity.dll

i would guess the use of WshShell.Run xcalcs...etc
would be best done just after you have .SetInfo'd and before the 'Next'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top