Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting Permissions to Home folders

5 views
Skip to first unread message

Masti

unread,
Apr 14, 2008, 4:40:00 PM4/14/08
to
Hi,
We have a storage location where we have all users home folders,whenever a
user is created in Active directory home folder will be created automatically
by the script. but the script doesnt assign any permissions to the folder.

The script what i need is it has took at all the home folders on the filer
and if user id matches with home folder name it has to assign full access to
administrator and modify permission to user ...if the settings are already
assigned then it has to skip to next folder ...this should be alooop until it
finishes checking all folders.

Can anyone help me with the script please .

Thanks in advance .

Masti

Pegasus (MVP)

unread,
Apr 14, 2008, 5:24:10 PM4/14/08
to

"Masti" <Ma...@discussions.microsoft.com> wrote in message
news:FAFA94EE-87CF-4808...@microsoft.com...

You could run this batch file:
01. @echo off
02. echo Permissions modified on %date% at %time% > c:\perms.txt
03. for /d %%a in (*.*) do call :Sub %%a
04. notepad c:\perms.txt
05. goto :eof
06.
07. :Sub
08. cacls "%*" | find /i "%*:" || goto Action
09. echo Skipping "%*"
10. goto :eof
11.
12. :Action
13. echo Modifying "%*" >> c:\perms.txt
14. echo cacls "%*" /t /e /c /g "%*":F administrators:F "domain admins":F
system:F
15. echo cacls "%*" /t /e /c /r everyone
16. pause

Please note:
- You must run this batch file while logged on as
domain administrator.
- You must run it from a Command Prompt and while
in the parent folder that holds your user folders.
- When you're happy with what it would do then you must
activate it by removing the words "echo" in lines 14. and 15,
and the words "pause" in line 16.


Masti

unread,
Apr 14, 2008, 6:09:00 PM4/14/08
to
Hi,

Instead of running this manually as batch file can we run this in scheduled
task ..so that every week of specified day i can have this script run and do
the need ful , is it possible ?

Running from the command prompt would be manually running it .

I have this script which works but i need to specify the home name other
wise this doesnt do any good to me .Can you modify this script and help me
out please .

Script Starts here

Function SetPermissions()
Dim strHomeFolder, strHome, strUser
Dim intRunError, objShell, objFSO

strHomeFolder = "C:\Test"

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strHomeFolder) Then
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
& strHomeFolder & " /e /c /g everyone:F ", 2, True)

If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & strHomeFolder
End If
End If
End Function

Pegasus (MVP)

unread,
Apr 15, 2008, 1:51:06 AM4/15/08
to

"Masti" <Ma...@discussions.microsoft.com> wrote in message
news:8564132D-3390-48A2...@microsoft.com...

There is no reason you cannot run this batch file as a scheduled
task, provided that you specify the partent folder for the home
folders (see modified version below) and provided that the
account used for the scheduled task has sufficient privileges to
do the job. You must, of course, test the batch file before you
turn it loose under the Task Scheduler.
01. @echo off
02. set target="D:\User Data"
03. echo Permissions modified on %date% at %time% > c:\perms.txt
04. for /d %%a in (%target%\*.*) do call :Sub %%a
05. notepad c:\perms.txt
06. goto :eof
07.
08. :Sub
09. cacls "%*" | find /i "%*:" || goto Action
10. echo Skipping "%*"
11. goto :eof
12.
13. :Action
14. echo Modifying "%*" >> c:\perms.txt
15. echo cacls "%*" /t /e /c /g "%*":F administrators:F "domain admins:F"
system:F
16. echo cacls "%*" /t /e /c /r everyone
17. pause

You could also use your own VB Script in this form:

SetPermissions
Sub SetPermissions()


Dim strHomeFolder, strHome, strUser
Dim intRunError, objShell, objFSO

strHomeFolder = "D:\User Files"

Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolders = objFSO.GetFolder(strHomeFolder)
For Each objFolder In objFolders.SubFolders
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls.exe """ _
& strHomeFolder & "\" & objFolder.Name _
& """ /e /t /c /g everyone:F ", 2, True)
Next
End Sub

The script will need more work, e.g.
- In its current form it gives everyone full access. This is not
what you wanted as per your first post.
- It will process every folder, regardless of pre-existing permissions.
- I suspect it will need some work with the various double quotes in
the "run" method. I will leave it to you to finalise the code.

My preference is to use scripts when script functions are available,
and batch files when commands are available. IMHO mixing the
two creates unnecessarily complex programs that are difficult to
maintain. Since the core command in this case is cacls.exe, a batch
file seems to obvious choice.

Masti

unread,
Apr 22, 2008, 2:10:00 PM4/22/08
to
Hi,
I have created this script and for some reason the script assigns only full
permssions to user home folder i am not able to assign only Modify permission
. what i need is give Adminsitrator full access and user modify permission
only instead of full access .
Can you please check and let me know what i am doing wrong in this script .

option explicit

dim i
dim Fol
dim objFSO
dim objFolder
dim colSubFolders
dim objSubFolder

Set objFSO = CreateObject("Scripting.FileSystemObject")

for i = 1 to 2
If i = 1 Then
Set objFolder = objFSO.GetFolder("\\Storage Location1")
Else
Set objFolder = objFSO.GetFolder("\\Storage Location2")
End If

for each objSubfolder in objfolder.SubFolders
If objSubFolder.Name = "praveen" then
'MsgBox objSubFolder.Path
SetPermissions objsubfolder.Path, objSubFolder.Name
End if
next
next

msgbox "done"

Function SetPermissions(strHomeFolder, name)
Dim strHome, strUser


Dim intRunError, objShell, objFSO
'strHomeFolder = "C:\Test"

'MsgBox strHomeFolder


Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strHomeFolder) Then

intRunError = objShell.Run("%COMSPEC% /C Echo Y| cacls " _
& strHomeFolder & " /E /C /G " & name & ":M ", 2, True)



If intRunError <> 0 Then
Wscript.Echo "Error assigning permissions for user " _
& strUser & " to home folder " & strHomeFolder
End If
End If
End Function

Any help would be appreciated.

Thanks

Masti

Pegasus (MVP)

unread,
Apr 22, 2008, 2:45:34 PM4/22/08
to
If you embed command line code in your VB script then your
first step must be to test this code from the Command Prompt.
After you get it to work there, you can put it into your VB Script.

Let's have a look at the full cacls commands you ran at the
Command Prompt!

A brief comment on your code: Having a for/next loop like this one:
=============


for i = 1 to 2
If i = 1 Then
Set objFolder = objFSO.GetFolder("\\Storage Location1")
Else
Set objFolder = objFSO.GetFolder("\\Storage Location2")
End If

for each objSubfolder in objfolder.SubFolders
If objSubFolder.Name = "praveen" then
'MsgBox objSubFolder.Path
SetPermissions objsubfolder.Path, objSubFolder.Name
End if
next
next

============
doesn't make much sense. You're not really counting anything -
you're only executing the same code twice. Your idea could be
much more clearly expressed like so:
============
TreatFolder "\\Storage Location1"
TreatFolder "\\Storage Location2"
MsgBox "done"

Sub TreatFolder(FolderName)
Set objFolder = objFSO.GetFolder(FolderName)
For Each objSubFolder In objFolder.SubFolders
If objSubFolder.Name = "praveen" _
Then SetPermissions objSubFolder.Path, objSubFolder.Name
Next
End Sub
===========


"Masti" <Ma...@discussions.microsoft.com> wrote in message

news:679548C2-C9AC-45AF...@microsoft.com...

Masti

unread,
Apr 22, 2008, 4:20:01 PM4/22/08
to
Hi,

I did test the code it is working fine and only problem i am running into is
it assigns full permission to folder other than modify permission, i think
some where in the code i specified wrong switch

Masti

Pegasus (MVP)

unread,
Apr 22, 2008, 4:58:57 PM4/22/08
to

"Masti" <Ma...@discussions.microsoft.com> wrote in message
news:C2CC4925-B656-4901...@microsoft.com...

> Hi,
>
> I did test the code it is working fine and only problem i am running into
> is
> it assigns full permission to folder other than modify permission, i think
> some where in the code i specified wrong switch
>
> Masti
>

This is why I would like to see the cacls.exe commands you used.


0 new messages