The takeown.exe only applies to administrators accounts.
my objective is using the foldername to take ownership of the folder. moreover i have multiple folders of all different name i like run a script to take the name of all folders individually and give it ownership of those individual folder
heres what i mean. folder name is jdoe
using the folder name i like jdoe to take ownership. remember the currently ownership is administrator.
set fso = CreateObject("Scripting.FileSystemObject") set shell = CreateObject("Wscript.Shell") set folder = fso.GetFolder("c:\test") '<---Profile Folder on your server
for each Subfolder in folder.subfolders currentUser = subfolder.name shell.run ("C:\cacls.exe ..........." ¤tUser ..... & subfolder.folder) '<---type in here the dos command for cacls.exe next '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TakeOwn.exe tool was very forceful and gets the job done where XCACLS fails.
Download the TAKEOWN.EXE from Microsoft and XCACLS (see the link above) if you don't have it already. I would copy these files (TakeOwn.exe and XCACLS.vbs) to C:\Windows. So It's accessible from anywhere.
Run TakeOwn.exe to to take ownership of the folder and it's contents
TakeOwn /F C:\Path\FolderORFileName /A /R /D Y
/F <filename> is to specify the file or folder name
/A is take ownership to local Administrators group
/R is for recursively take ownership of all sub folders and files
/D Y (or /D N) is to accept any questions for change, otherwise you have to manually type Yes or No.
Run XCACLS.vbs to assign "inheritance" bit on all sub-folders and files.
/I Enable is to enable the Inheritance flag, so it will inherit the permission from parent folder
/SPEC B is to apply the changes to all sub folders and files
/G Administrators:F is to assign manual permission to local administrator group to full access. For odd reason, I have to supply this switch to process all sub folders and files and enabling inheritance flag.
/F is to process files
/S is to process sub folders
/T is to traverse through the while directory Tree
I would add /QQ or /Q for quite mode, because I don't want to see the results for every file and folders
To make it easy, I created a batch file with the following commands
TakeOwn /F %1 /A /R /D Y XCACLS %1 /G Administrator:F /I Enable /SPEC B /F /T /S /QQ
Call the batch file as "RefreshPermissions.bat". I would run the Batch file with the folder or file as parameter. E.g.,
I hope this solution also works for you. If it is, leave me a reply.
Microsoft is conducting an online survey to understand your opinion of the Technet Web site. If you choose to participate, the online survey will be presented to you when you leave the Technet Web site.