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
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.
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
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.
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
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...
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.