Jump to content

How to Take Ownership & Grant Permissions to Access Files & Folder in Windows 7


ricky
 Share

Recommended Posts

Hello,

it's possible to code in autoit those information in this page :

http://www.blogsdna.com/2159/how-to-take-ownership-grant-permissions-to-access-files-folder-in-windows-7.htm

Thanks in advance for you help

Link to comment
Share on other sites

yes you can. If you noticed they show a different way to do this with a context click. It involves modifying the registry and then context clicking on the file you want to take ownership of. It would be a simple matter then to make an adjustment to the reg file they provide you so one could use an AutoIt script to do what you have in mind.

Link to comment
Share on other sites

To set permissions or take ownership of files/folders, I always use the program SetACL and embed that in my exe with FileInstall. Works better than xcalcs with file/folder inheritance. I can't remember why now though, but there was an article somewhere about it.

Link to comment
Share on other sites

Try this:

;Coded by UEZ 2010
#RequireAdmin
$objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")

$file = FileOpenDialog("Select file to reset ownership from current user.", "", "(*.*)")
If @error Then Exit
$res = Set_OwnerShip($file)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $res = ' & $res & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console

Func Set_OwnerShip($file)
    $file = StringReplace($file, "\", "\\")
    Local $colItems, $colItem
    $colItems = $objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = '" & $file & "'", "WQL", 0x30)
    If IsObj($colItems) Then
        For $objItem In $colItems
            $objItem.TakeOwnerShipEx
        Next
        Return 1
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

Or try the command line subinacl from Microsoft.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Couple of subinacl eg

you will obviously need the subinacl exe to make this work

$source = "your source dir"
$subinacl = @WorkingDir & "\subinacl.exe"

RunWait(@ComSpec & " /c " & $subinacl & " /subdirectories " & $source & "*.*" & " /setowner=" & @UserName)
RunWait(@ComSpec & " /c " & $subinacl & " /subdirectories " & $source & "*.*" & " /grant=" & @UserName & "=f")

and ive done attrib this way before

If FileExists ( $source & "Perflogs") Then FileSetAttrib( $source & "Perflogs", "-H", 1)
Edited by Chimaera
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...