Page 1 of 2

reset ntfs partition permissions

Posted: 14 Jul 2014 20:39
by yusef88
hi
i need a tool can integrate to right click menu and reset ntfs permissions for files and folders any suggestions?
===
windows xp

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 20:49
by Marco
So no command line?

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 20:55
by yusef88
well, it will be good if it can reset the entire partition
====
even individual folders it would be good :x

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 21:28
by Marco
I was lucky to download FileACL 3.0.1.6 some years ago, when the website was still up. http://archive.today/pnb1o
These are the line that I use, in sequence, to totally reset the permissions of a drive X. You have to run them with admin privileges.

Code: Select all

fileacl X:\ /o Administrator /sub /files /force
fileacl X:\ /s Administrator:F /replace /force
fileacl X:\ /replace /inherit /noroot /sub /files /force

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 21:43
by yusef88
wow, very easy to use.very thanks dear Marco
==
if i put it in <xydata> directory possible to make it work with selected folders by XY scripts?
=
or for simplification, make the script let me choose which drive letter to reset

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 21:53
by Marco
Yes

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 22:00
by yusef88
small problem i just test it on a folder, after applying to 2 partitions i lost access to them and i had to restore their permissions manually :roll:

Re: reset ntfs partition permissions

Posted: 14 Jul 2014 22:07
by Marco
Natural. You first reset the permissions with those lines: the Admin obtains full access. Then you should grant full access to yourself as well.
You could also try by substituting Administrator with Everyone in those lines (never tested myself tho).

Re: reset ntfs partition permissions

Posted: 15 Jul 2014 01:53
by yusef88
i found something interesting "Bypass NTFS permissions" http://www.hobeanu.com/accessgain/
now i need your help :) to make this command work with selected folder

Code: Select all

CACLS folderpass /t /C /G Everyone:F
=====
update i made a batch file and use it by openwith script :D
ه really appreciate your help Marco :whistle:

Re: reset ntfs partition permissions

Posted: 15 Jul 2014 09:30
by highend

Code: Select all

    foreach($folder, "<get SelectedItemsPathNames |>", "|") {
        if (exists($folder) == 2) { run """%COMSPEC%"" /k CACLS ""$folder"" /T /C /G Everyone:F", 2, 0; }
    }

Re: reset ntfs partition permissions

Posted: 15 Jul 2014 10:57
by yusef88
good script..thanks highend :appl:

Re: reset ntfs partition permissions

Posted: 15 Jul 2014 11:21
by highend
I'm currently writing something more "sophisticated"...

It uses ICALCS (CALCS is deprecated since Vista...)
but it will need a helper application (because I don't use
an elevated XY instance all the time).

Let's see if I can solve it with a small .vbs script (no external tool would be required).

Btw, if the current "script" works for you, you should replace the "/k" with "/c" at least
if you don't want to create a lot of dos boxes when you select more than one folder.

Re: reset ntfs partition permissions

Posted: 15 Jul 2014 21:18
by yusef88
it works with folders only, this batch works with both files and folders and show if access is denied

Code: Select all

@echo off
:a
if exist "%~1\nul" cd /d %1&set sub=/T
title ResetNTFSPermissions CACLS
echo This will REPLACE all the NTFS permissions to EVERYONE incuding all subfolders
echo (or run the command manually with /E to Edit ACL instead of replacing it)
echo ---
echo CACLS %1 %sub% /C /G Everyone:F
echo ---
CACLS %1 %sub% /t /C /G Everyone:F
shift
set g=hiren%1
if %g%==hiren goto e
goto a
:e
Pause

Re: reset ntfs partition permissions

Posted: 19 Jul 2014 11:28
by highend
1. Autoelevating
2. Translations
3. Could be enhanced with an inputselect() to decide which commands should be executed

Code: Select all

    /*
        /T = Recusive
        /C = Continue in case of any file errors
        /Q = Don't show a message for each file / folder
        /grant:r = Replace permissions instead of adding them
        (OI) = Object inheritance (Vererbung für Dateien)
        (CI) = Container inheritance (Vererbung für Ordner)
        F = Full
    */

    // End if no files / folders are selected
    $selectedItems = "<get SelectedItemsPathNames |>";
    if ($selectedItems == "") {
        status "No item(s) selected, aborted!", "FF0000", "stop";
        end(true);
    }

    $batFile = "%TEMP%\~icacls.bat";
    $getAdminVBSFile = "%TEMP%\~GetAdmin.vbs";

    // Get client language
    $languageID = regexmatches(runret("""%COMSPEC%"" /c REG QUERY ""HKLM\SYSTEM\CurrentControlSet\Control\Nls\Language"" /v ""InstallLanguage"""), "\d{4}");

    // Translation
    $groupList = "Administrators|Users|Everyone";
    if ($languageID == "0407") { // German
        $localizedGroupList = "Administratoren|Benutzer|Jeder";
    } else { // Fallback to english
        $localizedGroupList = $groupList;
    }

    // Possible ICACLS commands
    $acl_Options = " /T /C /Q";
    $acl_Reset_Full = replacelist("/grant:r Everyone:(OI)(CI)F", $groupList, $localizedGroupList, "|");
    $acl_Add_Admin = replacelist("/grant Administrators:(OI)(CI)F", $groupList, $localizedGroupList, "|");
    $acl_Add_CurUser = "/grant %USERNAME%:(OI)(CI)F";

    // Edit this list if you want to add / remove commands to process
    // Ofc you need to add additional variables right over this comment...
    $aclProcessList = '$acl_Reset_Full|$acl_Add_Admin|$acl_Add_CurUser';

    $batchCommands = "";
    foreach($item, $selectedItems, "|") {
        $cmdOptions = "";
        foreach($entry, $aclProcessList, "|") {
            $entry = eval($entry); // Resove the variable names
            $cmd = "@ICACLS " . quote($item) . " " . $entry . $acl_Options;
            $cmdOptions = $cmdOptions . "@ECHO [Options: $entry]<crlf>" . $cmd . "<crlf>" . "@ECHO." . "<crlf>";
        }
        $batchCommands = $batchCommands . "@ECHO [$item]<crlf>" . $cmdOptions . "<crlf>" . "@ECHO.<crlf>@ECHO.<crlf>";
    }

    writefile($batFile, $batchCommands); // Write the .bat file

    $getAdminVBS = <<<>>>
        Set UAC = CreateObject("Shell.Application")
        UAC.ShellExecute "%COMSPEC%", "/k ""$batFile""", "", "runas", 1
>>>;

    writefile($getAdminVBSFile, trim($getAdminVBS));
    run """cscript"" ""$getAdminVBSFile""", , 0, 0;

Re: reset ntfs partition permissions

Posted: 19 Jul 2014 22:37
by yusef88
sorry to tell you it failed to unlock inaccessible file in win7 but Take ownership can
http://www.askvg.com/add-take-ownership ... ows-vista/