Jump to content

Recommended Posts

Posted (edited)

Hey,

You could give UDF a try :)

; #FUNCTION# ====================================================================================================================
; Name...........: _SetObjectOwner
; Description ...: Sets the owner of an object.
; Syntax.........:  _SetObjectOwner($oName, $_SE_OBJECT_TYPE, $AccountName)
; Parameters ....:  $oName   - The name or handle to the object. This can be a path to a file or folder, a registry key,
;                    + a service name, a process handle, etc. See the comments on the _SE_OBJECT_TYPE enum for more info.
;                    $_SE_OBJECT_TYPE (Optional) - The type of the object to set permissions. This must be one of the values of the
;                    +_SE_OBJECT_TYPE enum. The default is $SE_FILE_OBJECT (a file or folder).
;                    $AccountName (Optional) - The account name or SID string to set. the default is the administrators group.
;                        +Can be any user name or SID string, see GetSidStruct() for more info.
; Return values .: Success      - 1
;                  Failure      - 0 and sets @error
; Author ........: FredAI
; Modified.......:
; Remarks .......:
; Related .......: _GetSidStruct
; Link ..........:
; Example .......: _SetObjectOwner('C:\Example.txt')

Edited by Neutro
Posted (edited)

@Neutro, thanks a lot! While I was looking, I figured out an easy way:

$STYLEFILE=(@WindowsDir & '\Resources\Themes\Aero\aero.msstyles')
Run(@ComSpec & " /C " & 'TAKEOWN /F ' & $STYLEFILE, '', @SW_HIDE)
Run(@ComSpec & " /C " & 'icacls ' & $STYLEFILE & ' /grant administrators:F /t', '', @SW_HIDE)

But I noticed nobody is using it. Is something wrong with it? Doesn't work under some circumstances?

Edited by supraspecies
Posted

Seems good to me as well :)

Maybe using the Set ACL UDF will be faster since you do not need to call an external software (takeown & icalcs) to do this, but if it's just for a few files then it doesn't really matter i guess!

Posted (edited)

Ownership.reg:

RMB over the file/s to own.

Windows Registry Editor Version 5.00

;=============================================================================

;Take ownership Users

[HKEY_CLASSES_ROOT*shellown]
@="Users Ownership"
"NoWorkingDirectory"=""
"Icon"="C:ICOown.ico"

[HKEY_CLASSES_ROOT*shellowncommand]
@="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"

[HKEY_CLASSES_ROOTDirectoryshellown]
@="Users Ownership"
"NoWorkingDirectory"=""
"Icon"="C:ICOown.ico"

[HKEY_CLASSES_ROOTDirectoryshellowncommand]
@="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"

[HKEY_CLASSES_ROOTDriveshellown]
@="Users Ownership"
"NoWorkingDirectory"=""
"Icon"="C:ICOown.ico"

[HKEY_CLASSES_ROOTDriveshellowncommand]
@="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f "%1" /r /d y && icacls "%1" /grant Users:F /t"

;=============================================================================

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

@ careca

Already have that on my system, has nothing to do with AutoIT. I wanted my script to take ownership on its own. And even though I could make it click on mouse context menu option, it wouldn't be proper because it would work only for those who actually have that option in context menu.

Posted (edited)

I'm testing that UDF on a random system file, and no go.

#include <Permissions.au3>
#RequireAdmin
_GrantAllAccess(@WindowsDir & '\System32\advapi32.dll')

It works for non-system files (user-created), but on system files it does nothing for me. It reports success, but nothing changes. And yes, I'm running it as admin. I even have UAC turned off. Any ideas?

Actually - I'm wrong. Depends on files. Seems to work for Windows theme files, but DLLs in System32 - nope. I don't need my script to access them at the moment, but someday i might... So I'm asking.

P.S. If you're wondering what is all this for - customizing Windows 7 installation. Unattended.

 

@ UEZ

Appreciate it, trying now.

Edited by supraspecies
Posted

@ careca

Already have that on my system, has nothing to do with AutoIT. I wanted my script to take ownership on its own. And even though I could make it click on mouse context menu option, it wouldn't be proper because it would work only for those who actually have that option in context menu.

Yeah, but you could use the same commands in autoit.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

  • 3 months later...
Posted (edited)

Actually - I'm wrong. Depends on files. Seems to work for Windows theme files, but DLLs in System32 - nope. I don't need my script to access them at the moment, but someday i might... So I'm asking.

 

That day has come. I need to replace shellstyle.dll in System32 on first Windows 7 launch (post-install). Permission script above and takeown do not work with files located in System32. How can my script gain permissions needed to replace files in System32 folder?

In case youre wondering - not using it for any malicious purpose. I have customized my Windows and made an unattended install for it. This file contains modded Classic Theme for Windows, and I need my Windows to install with this theme by default.

Edited by supraspecies
Posted

safe mode?

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Posted

In Windows XP, it was known as Windows File Protection. Later it become Windows Resource Protection. This is perhaps the problem.

In XP you could replace the file in the dllcache folder and then the file in the system32 folder. In Vista+, I am not sure how it is done at this moment.

Posted
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

  • 2 weeks later...
Posted (edited)

Solved it (with a help from a friend). If anyone needs to know how to replace files in System32 (including x64 edition of Windows), here is the way:

#requireadmin
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 1)
$STYLEFILE=(@WindowsDir & '\System32\shellstyle.dll')
Run(@ComSpec & " /c " & 'TAKEOWN /F ' & $STYLEFILE, '', @SW_HIDE)
Run(@ComSpec & " /c " & 'cacls.exe ' & $STYLEFILE & ' /E /P BUILTIN\Administrators:F', '', @SW_HIDE)
DllCall("kernel32.dll", "int", "Wow64EnableWow64FsRedirection", "int", 1)
 

This will grant you all permissions to do whatever you wish.

Edited by supraspecies

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
  • Recently Browsing   0 members

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