Jump to content
Sign in to follow this  
ricky

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

Recommended Posts

ricky

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

Share this post


Link to post
Share on other sites
Bert

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.

Share this post


Link to post
Share on other sites
jazzyjeff

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.

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
Chimaera

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

Share this post


Link to post
Share on other sites
ricky

Thanks UEZ and Chimera, but norhing work on Windows 7!!!

jazzyjeff : You have a function?

Share this post


Link to post
Share on other sites
ricky

I can't change the title...

How can I do that also to delete a registry key?

Edited by ricky03

Share this post


Link to post
Share on other sites
hannes08

Deleting a registry key: RegDelete()

You might also try using icacls.exe (at least that's what I use for Windows Server 2008+) :mellow:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites
ricky

Nobody can help me ?

@Hannes123 : do you have examples?

Deleting a registry key: RegDelete()

Sometimes it doesn't work, because I don't have the right and I use #requireadmin

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.