Traskiz Posted May 5, 2016 Share Posted May 5, 2016 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... Link to comment Share on other sites More sharing options...
Trong Posted May 5, 2016 Share Posted May 5, 2016 (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 May 5, 2016 by Trong #RequireAdmin Regards, Link to comment Share on other sites More sharing options...
Traskiz Posted May 5, 2016 Author Share Posted May 5, 2016 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 Link to comment Share on other sites More sharing options...
Trong Posted May 5, 2016 Share Posted May 5, 2016 (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 May 5, 2016 by Trong X64 Regards, Link to comment Share on other sites More sharing options...
Traskiz Posted May 5, 2016 Author Share Posted May 5, 2016 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! Link to comment Share on other sites More sharing options...
Traskiz Posted May 8, 2016 Author Share Posted May 8, 2016 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...). Link to comment Share on other sites More sharing options...
AutoBert Posted May 8, 2016 Share Posted May 8, 2016 Try RunAs example from Helpfile. Did it start NotePad? Try also starting permission.exe in a CMD-session. Did this start. Link to comment Share on other sites More sharing options...
Traskiz Posted May 8, 2016 Author Share Posted May 8, 2016 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? Link to comment Share on other sites More sharing options...
AutoBert Posted May 8, 2016 Share Posted May 8, 2016 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. Link to comment Share on other sites More sharing options...
Traskiz Posted May 8, 2016 Author Share Posted May 8, 2016 Its starting, but without admin rights when using RunAs()... When starting cmd - run as administrator, then it works... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now