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

Make all subfolders hidden shares

Status
Not open for further replies.

FPTech619

IS-IT--Management
Nov 21, 2011
4
US
Hello All,

I recently re-raided my file server and upgraded to Server 2008 R2 Enterprise. After the installation and updates were completed I restored all of my folders back to the server. I would like to use a script to share all of the home folders and to set the permissions. I've found scripts on this site that will do that but I would also like the script to hide the folders using the "$". The home folders are named by the user's username. I would like to give domain admins, and the user full control to the share.
I am somewhat a beginner at scripting, and I'm not entirely sure that VB is going to be able to accomplish this, but if anybody has any suggestions for me please let me know.

Thanks,
 
Your description is a little vague. Also seeing what code you have would help so that we can see what you've tried.

In the mean time, may I make a few suggestions:

1) Use of the $ sign on a folder will not hide it from view. It will hide the a folder that is shared though
2) Using Server 2008 R2, you should be able to use access based enumeration so that the user's can only see what they have permission to
 
I've been working on the script to do this for a while now and it is now a combination of three scripts.

The first script "shareallsubfolders.vbs" that I run on the root of the folder with all of the users home directories in it, will declare the variables, perform validation, and then call the other two scripts while passing the appropriate arguments to them.

The second script "setsharepermissions.bat" will create the hidden share, and set the appropriate share permissions on the folder.

The third script "setsecpermissions.vbs" sets the appropriate NTFS permissions on the share.

I then map the users profile's to \\server\%username%$.

The scripts seem to be working correctly except the "setsharepermissions.bat" which will not allow me to give domain admins full control on the folder. I believe that it has something to do with the space in the group name. If anybody has any suggestions on the proper syntax for this please help.

Thanks,

*shareallsubfolders.vbs

set objFSO = createobject("Scripting.FileSystemObject")
On Error Resume Next

RootFolder = inputbox("please enter the root of the partent folder")

'***** Perform some basic validation *****
if not objFSO.FolderExists(RootFolder) then
wscript.echo "Invalid Folder"
wscript.quit
end if
if mid(RootFolder,1,2)="\\" then
wscript.echo "UNC Paths are not supported"
wscript.quit
end if

set objRootFolder = objFSO.GetFolder(rootfolder)
for each fldr in objRootFolder.SubFolders
sharefolder fldr.path, fldr.name
next

wscript.echo "All folders have been shared"

sub shareFolder(byval folderPath,shareName)
'get the name of the folder to resolve the username
dim strUser
strUser = "DOMAINNAME\" & shareName
'use a $ to hide the share
shareName = shareName & "$"
'Call other two scripts to set share and NTFS permissions
Dim objShell
Set objShell = CreateObject("wscript.Shell")
objShell.Run ("D:\scripts\setsharepermissions.bat " & shareName & " " & folderPath & " " & strUser)
objShell.Run ("D:\scripts\setsecpermissions.vbs " & folderPath & " " & strUser)
'wscript.echo (shareName & "has been shared with the correct permissions")

end sub

*setsharepermissions.bat

echo off
REM command shares a given folder with a given share name and grants domain administrators full control for share permissions.
REM %1 is the first argument or sharname
REM %2 is the second argument or folder path.
REM Note that this does not set NTFS permissions

NET SHARE %1=%2 /remark:"Shared by Remote Command" /GRANT:"DOMAIN\Domain admins", FULL /GRANT:"%3",FULL

*setsecpermissions.vbs

Option Explicit
Dim strHomeFolder, strHome, strUserName
Dim intRunError, objShell, objFSO, args

Set objShell = CreateObject("Wscript.Shell")
Set args = WScript.Arguments
'Argument 1 is the home folder
strHomeFolder = args.Item(0)
'Argument 2 is the UserName
strUserName = args.item(1)

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strHomeFolder) Then
'Assign NTFS permissions to folder.
intRunError = objShell.Run("%COMSPEC% /C Echo Y| cacls " & strHomeFolder & " /T /C /G ""Domain Admins"":F " & strUserName &":F", 2, True)
If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " & strUserName & " to home folder " & strHomeFolder
End If
End If

WScript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top