Traskiz

change program files folder permissions

10 posts in this topic

Hello, I want to change permissions in %programfiles%\test(one of application requires that:():

#include <Process.au3>
_RunDos("cacls %programfiles%\test /t /e /g Everyone:f")

When I use other folder I can achieve that:

#include <Process.au3>
_RunDos("cacls c:\test /t /e /g Everyone:f")

Please help me, I need to do that in my company for many PC's(windows 10 64 bit). I will use RunAs() to elevate script...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try:

#RequireAdmin

_TakeOwnership(@ProgramFilesDir&"\test")
_TakeOwnership("C:\test")

Func _TakeOwnership($xFile)
    If Not FileExists($xFile) Then Return SetError(1, 0, $xFile)
    If StringInStr(FileGetAttrib($xFile), 'D') <> 0 Then
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '" /R /D Y', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /T /C /G Administrators:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Administrators:F /T /C /Q', '', @SW_HIDE)
        Return SetError(0, 0, 0)
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '"', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /C /G Administrators:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Administrators:F /Q', '', @SW_HIDE)
        Return SetError(0, 0, 1)
    EndIf
    Return $xFile
EndFunc   ;==>_TakeOwnership

 

Edited by Trong
#RequireAdmin

Regards,
 

Share this post


Link to post
Share on other sites
9 minutes ago, Trong said:

Try:

#RequireAdmin

_TakeOwnership(@ProgramFilesDir&"\test")
_TakeOwnership("C:\test")

Func _TakeOwnership($xFile)
    If Not FileExists($xFile) Then Return SetError(1, 0, $xFile)
    If StringInStr(FileGetAttrib($xFile), 'D') <> 0 Then
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '" /R /D Y', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /T /C /G Administrators:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Administrators:F /T /C /Q', '', @SW_HIDE)
        Return SetError(0, 0, 0)
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '"', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /C /G Administrators:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Administrators:F /Q', '', @SW_HIDE)
        Return SetError(0, 0, 1)
    EndIf
    Return $xFile
EndFunc   ;==>_TakeOwnership

 

It not worked :(

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Everyone

#RequireAdmin

If StringInStr(@OSArch, "64") Then DllCall("kernel32.dll", "boolean", "Wow64EnableWow64FsRedirection", "boolean", 0)

_TakeOwnership("C:\Program Files (x86)\test")
_TakeOwnership("C:\Program Files\test")
_TakeOwnership("C:\test")

Func _TakeOwnership($xFile)
    If Not FileExists($xFile) Then Return SetError(1, 0, $xFile)
    If StringInStr(FileGetAttrib($xFile), 'D') <> 0 Then
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '" /R /D Y', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /T /C /G Everyone:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Everyone:F /T /C /Q', '', @SW_HIDE)
        Return SetError(0, 0, 0)
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '"', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /C /G Everyone:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Everyone:F /Q', '', @SW_HIDE)
        Return SetError(0, 0, 1)
    EndIf
    Return $xFile
EndFunc   ;==>_TakeOwnership

 

Edited by Trong
X64

Regards,
 

Share this post


Link to post
Share on other sites
6 minutes ago, Trong said:

Everyone

#RequireAdmin

_TakeOwnership(@ProgramFilesDir & "\test")
_TakeOwnership("C:\test")

Func _TakeOwnership($xFile)
    If Not FileExists($xFile) Then Return SetError(1, 0, $xFile)
    If StringInStr(FileGetAttrib($xFile), 'D') <> 0 Then
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '" /R /D Y', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /T /C /G Everyone:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Everyone:F /T /C /Q', '', @SW_HIDE)
        Return SetError(0, 0, 0)
    Else
        RunWait(@ComSpec & ' /c takeown /f "' & $xFile & '"', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c Echo y|cacls "' & $xFile & '" /C /G Everyone:F', '', @SW_HIDE)
        RunWait(@ComSpec & ' /c icacls "' & $xFile & '" /grant Everyone:F /Q', '', @SW_HIDE)
        Return SetError(0, 0, 1)
    EndIf
    Return $xFile
EndFunc   ;==>_TakeOwnership

I tried Everyone before, but I was checking for C:\program files\test, but when I checked C:\program files (x86)\test permissions was changed! :)  this is what I needed, thank you! :)

 

Share this post


Link to post
Share on other sites

HELP! I cant run that script as administrator...  with this script on windows 10...:

Local $sUserName = "Username"
Local $sPassword = "Password"
Local $sDomain = "Domain"
RunAs($sUserName, $sDomain, $sPassword, 2, "permissions.exe", "", @SW_SHOWMAXIMIZED)

I can do that with installations(adobe reader, firefox, etc...).

Share this post


Link to post
Share on other sites

Try RunAs example from Helpfile.  Did it start NotePad?

Try also starting permission.exe in a CMD-session. Did this start.

Share this post


Link to post
Share on other sites
58 minutes ago, AutoBert said:

Try RunAs example from Helpfile.  Did it start NotePad?

Try also starting permission.exe in a CMD-session. Did this start.

Its starts notepad

if I run permission.exe  with command promp (Admin) it works... I think this is because permission.exe  is not trusted or something? :(

Share this post


Link to post
Share on other sites

NotePad is started as it is found in the searchpath. If Permission.exe starting in CMD-window then it also starting with RunAs using a Admin.

Share this post


Link to post
Share on other sites

#10 ·  Posted

Its starting, but without admin rights when using RunAs()...
When starting cmd - run as administrator, then it works... :(


 

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