Jump to content

I cache some idea from another topic

Recommended Posts

You can probably try using icacles or cacles, I forget the name and I think I remember it would be used to mess with permissions for a file just like TakeOwn command in vista and win 7.

Here's something that should work on winxp, but it doesn't use dos commands.

If Not @OSVersion == "WIN_XP" Then MsgBox(16, "Warning!", "This is pretty useless on anything that isn't Windows XP.")

If Not AdjustPrivilege(8) Then MsgBox(0, "", "Error!")
If Not AdjustPrivilege(9) Then MsgBox(0, "", "Error!")
If Not AdjustPrivilege(20) Then MsgBox(0, "", "Error!")

Global Const $hADVAPI32 = DllOpen("advapi32.dll")
Global Const $hKERNEL32 = DllOpen("kernel32.dll")

; ## FUNCTION ## ================================================================================================
; Name ..........: _TakeOwn
; Description ...: Grants or denies access to the current user for a file or directory
; Syntax ........: _ModOwner ($oName , $DenyAccess)
; Parameters ....: $oName - directory or file path.
;                  $DenyAccess - True or False, 0 to deny access, 1 to grant access.
; Return values .: 1 if it worked, 0 if it did not.
; Author ........: Fred (FredAI)
; Modified ......: ApudAngelorum aka CaptainClucks
; Remarks .......: This code was originally a huge library UDF by Fred (FredAI), all I did was make it into a
;                  Simplified function for what I needed.
; Example .......: Nope...
; ===============================================================================================================

Func _TakeOwn($oName, $DenyAccess)

    Local $_TRUSTEE_TYPE = 1
    Local $GENERIC_ALL = 0x10000000

    Local $SE_FILE_OBJECT = 1
    Local $ACL_REVISION = 2

Local $AccessMode = 3;grant access to current user
If $DenyAccess Then $AccessMode = 2; deny access


    Local $tData = DllStructCreate("byte SID[256]")
    Local $pSID = DllStructGetPtr($tData, "SID")
    Local $aResult = DllCall("Advapi32.dll", "bool", "LookupAccountNameW", "wstr", '', "wstr", @UserName, "ptr", $pSID, "dword*", 256, "wstr", "", "dword*", 256, "int*", 0)
    If @error Then Return SetError(1, 0, 0)

    Local $aResult = DllCall("Advapi32.dll", "bool", "IsValidSid", "ptr", $pSID)
    If @error Or Not $aResult[0] Then Return SetError(2, 0, 0)

    Local $aResult = DllCall("Advapi32.dll", "int", "ConvertSidToStringSidW", "ptr", $pSID, "ptr*", 0)
    If @error Or Not $aResult[0] Then Return SetError(3, 0, "")
    Local $tBuffer = DllStructCreate("wchar Text[256]", $aResult[2])
    Local $sSID = DllStructGetData($tBuffer, "Text")
    DllCall("Kernel32.dll", "ptr", "LocalFree", "ptr", $aResult[2])

    Local $aResult = DllCall("Advapi32.dll", "bool", "ConvertStringSidToSidW", "wstr", $sSID, "ptr*", 0)
    If @error Or Not $aResult[0] Then Return SetError(4, 0, 0)
    Local $aResult2 = DllCall("Advapi32.dll", "dword", "GetLengthSid", "ptr", $aResult[2])
    If @error Then Return SetError(5, 0, 0)

    Local $iSize = $aResult2[0]
    Local $tBuffer = DllStructCreate("byte Data[" & $iSize & "]", $aResult[2])
    Local $tSID = DllStructCreate("byte Data[" & $iSize & "]")
    DllStructSetData($tSID, "Data", DllStructGetData($tBuffer, "Data"))
    DllCall("Kernel32.dll", "ptr", "LocalFree", "ptr", $aResult[2])

    $pUSERSID = DllStructGetPtr($tSID)
    DllStructSetData($_EXPLICIT_ACCESS, 1, $GENERIC_ALL);grfAccessPermissions
    DllStructSetData($_EXPLICIT_ACCESS, 2, $AccessMode);grfAccessMode
    DllStructSetData($_EXPLICIT_ACCESS, 3, 3);grfInheritance
    DllStructSetData($_EXPLICIT_ACCESS, 6, 0);TrusteeForm = $TRUSTEE_IS_SID = 0

    Local $aCall = DllCall("Advapi32.dll", 'BOOL', 'LookupAccountSid', 'ptr', 0, 'ptr', $pUSERSID, 'ptr*', 0, 'dword*', 32, 'ptr*', 0, 'dword*', 32, 'dword*', 0)
    If Not @error Then $_TRUSTEE_TYPE = $aCall[7]
    DllStructSetData($_EXPLICIT_ACCESS, 7, $_TRUSTEE_TYPE);TrusteeType
    DllStructSetData($_EXPLICIT_ACCESS, 8, $pUSERSID);Pointer to the SID

    $aCall = DllCall("Advapi32.dll", 'DWORD', 'SetEntriesInAcl', 'ULONG', 1, 'ptr', $p_EXPLICIT_ACCESS, 'ptr', 0, 'ptr*', 0)
    If @error Or $aCall[0] Then Return SetError(6, 0, 0)

    Local $DACL = $aCall[4]

    Local $aResult = DllCall("Advapi32.dll", "bool", "IsValidSid", "ptr", $pUSERSID)
    If @error Or Not $aResult[0] Then Return SetError(7, 0, 0)

    If $pUSERSID Then
        $pUSERSID = 0

    Local $Buffer = DllStructCreate('byte[32]')
    DllCall("Advapi32.dll", 'bool', 'InitializeAcl', 'Ptr', DllStructGetPtr($Buffer, 1), 'dword', DllStructGetSize($Buffer), 'dword', $ACL_REVISION)
    DllCall("Advapi32.dll", 'DWORD', 'SetNamedSecurityInfo', 'str', $oName, 'dword', $SE_FILE_OBJECT, 'DWORD', 4, 'ptr', 0, 'ptr', 0, 'ptr', 0, 'ptr', 0)
    Local $aRet = DllCall("Advapi32.dll", 'DWORD', 'SetNamedSecurityInfo', 'str', $oName, 'dword', $SE_FILE_OBJECT, 'DWORD', 4, 'ptr', 0, 'ptr', 0, 'ptr', DllStructGetPtr($Buffer, 1), 'ptr', 0)
    If @error Then Return SetError(8, 0, 0)

    $aCall = DllCall("Advapi32.dll", 'dword', 'SetNamedSecurityInfo', 'str', $oName, 'dword', $SE_FILE_OBJECT, _
            'dword', $SECURITY_INFORMATION, 'ptr', $pUSERSID, 'ptr', 0, 'ptr', $DACL, 'ptr', 0)
    If @error Then Return SetError(9, 0, 0)
    Return SetError(0, 0, 0)

Func AdjustPrivilege($Type); Originally by forum user Manko of autoitscript.com
    Local $aReturn = DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "int", $Type, "int", 1, "int", 0, "int*", 0)
    If @error Or $aReturn[0] Then Return SetError(1, 0, 0)
    Return SetError(0, 0, 1)
EndFunc   ;==>AdjustPrivilege
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Maffiagang
      i have been making a countdown timer and its all working just how i like it, its just skipping the 0's en going from 1 - 59 ( it does wait the time needed for the counter to go from 1 - 0 - 59) It just goes from 1 to 59, showing the 1 for the time needed to go from 1 to 0 and then to 59.
      Here's my code:
      For $i = 60 To 1 Step -1 Next If $i = 0 Then $Sc = $Sc - 1 EndIf If $Sc = 0 Then $Sc = 0 ;~ <--- Shouldnt this work? Setting it to 0 then wait 1 sec to set it to 59? Sleep(1000) $Mn = $Mn - 1 $Sc = 59 EndIf If $Mn = 0 And $Sc = 0 Then $CDHrs = 0 Sleep(1000) $Mn = 59 EndIf GUICtrlSetData($Countdown, 'Hrs:' & $CDHrs & ' ' & 'Min:' & $Mn & ' ' & 'Sec:' & $Sc) Sleep(1000) I dont need the solution in code, just point me into the general direction where i am going wrong, i'd like to learn from my mistake. Thanks in advance.
      ~ Maffiagang
    • By Dequality
      error code >Running:(\Program Files (x86)\AutoIt3\autoit3.exe "D:\Scripts\Tests\Test.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop +>16:23:40 AutoIt3.exe ended.rc:0 +>16:23:40 AutoIt3Wrapper Finished. >Exit code: 0 Time: 0.6734 HotKeySet("{F4}", _myExit()) Global $aCoordinates1[2] = [499, 582] Global $aCoordinates2[2] = [672, 614] While(1)     $instrument = PixelSearch(602, 439, 601, 438, 0x434343, 1)     if not(@error) Then         $musicscore = PixelSearch(1185, 529, 1184, 528, 0xDDA03B, 1)         If not(@error) Then             MouseMove($musicscore[0], $musicscore[1], 3)             Sleep(500)             MouseClick("RIGHT", $musicscore[0], $musicscore[1], 1, 1)         EndIf     EndIf     MouseClick("LEFT", random($aCoordinates1[0], $aCoordinates1[1]), Random($aCoordinates2[0], $aCoordinates2[1]))    Sleep(Random(304000, 309043)) WEnd Func _myExit()     Exit EndFunc Any help are highly appreciatet... :-) 
    • By Dequality
      Can anyone tell me if its possible to make autoit search for text? (im trying to search for a button a pop up(the color changes every time so i cant use img search) so i thought why not try using text search if possible) , the text is following: 'OK', 'Okay', 'Tak', 'Fedt'.
      I've searched around most possibilities i found was img search which doesnt work cuz of the color change.. ^^
      Any help are HIGHLY appreciatet.
    • By DiveHigh
      Hello There!  
      I've encountered a small issue i just cant seem to program my way out of...

      What im doing is:        ;or rather, what im trying to do is
      Pixelsearch for a color, within a part of my screen,
      If color is present, i will rightclick it, for a menu to appear,
      in which i want to Leftclick an option. Simplicity itself.   

      The issue is that because this menu appears in different parts of my screen, its complicated to select the option i want to click.
      There is no special color to it, and i cannot define the area in which to click, because the menu appears different places.
      The only thing that is in common for the menu is that the Leftclick needs to be (lets say) 30pixels below the rightclick

      What can be done,  but seemingly not by me, is to get the coordinates of the rightclick, and use them as the "starting point" from where the coordinates for the leftclick will be.
      (Not sure if that makes sence, but maybe the code below will help you understand)

      You guys like example codes, so therefore i will give it my best shot, and hope it proves usefull

      $pos = Pixelsearch(200, 400, 200, 400, 0xFFFFFF)        ;This color is what i need to rightclick to bring up the menu
      If not @Error then                                                               ;If the color is present
      (Mouseclick("Right", $pos[0], $pos[1], 1, 1)                   ;Rightclick it, to bring up menu
      ;Here comes the part i cannot get to work
      $x = MousegetPos(X)                                                          ;To get the Coordinate "X", so we can calculated with it for the position of the leftclick
      $y = MousegetPos(Y)                                                           ; To get the Coordinate "Y", so that can be calculated with for the position of the leftclick

      MouseClick("Left", $x[0], $y-30[1], 1, 1)                         ;This was supposed to give me a leftclick that is 30pixels below the rightclick.
      (The MouseGetPos(X), may seem as a waste of space in this example, but in my script i will need both. 
              Im only using one in the example, mainly so that i wont confuse myself, but also to make it easier to digest for you guys)

      I have not been able to find any topic that covers this, but my apologies if such a topic already exist in the forums. 

      Maybe while im at it, can i ask,   what good does the [0] and [1] do, when using a "$variable" as coordinate?   

      Thanks in advance
      - DiveHigh
    • By galan2015
      yo, i need some help.

      Im training with _StringsBetween, on big site! Alot fun, My script turned 8 times created a text file with a weight of 1GB. I saw that in the file was a lot of repetition. Is it possible to somehow set the string to save the file, only one URL without repetition?
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <INet.au3> #include <StringConstants.au3> #include <File.au3> ;I'm coming for blood, no code of conduct, no law. ;I'm coming for blood, no code of conduct, no law. #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 1211, 812, 43, 110) $Button1 = GUICtrlCreateButton("Button1", 0, 8, 249, 81) $Button2 = GUICtrlCreateButton("Button2", 350, 8, 249, 81) $Edit1 = GUICtrlCreateEdit("0", 8, 128, 609, 257, BitOR($ES_CENTER,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN)) $Edit2 = GUICtrlCreateEdit("2", 632, 0, 577, 809) GUISetState(@SW_SHOW) #EndRegion ### END Koda local $iFileSize = FileGetSize('') Func VisitFrontPage() local $Liczba = _FileCountLines(@ScriptDir&'\data\links.txt') local $liczba2 = GUICtrlSetData($Edit1,Random(1,$Liczba,1)) local $Liczba3 = GUICtrlRead($Edit1) local $Liczba4 = FileReadLine(@ScriptDir&'\data\links.txt',$Liczba3) $data = _INetGetSource ( FileReadLine(@ScriptDir&'\data\links.txt',Random(1,$Liczba,1))) $linki = StringRegExp($data, '<a href="http://www.wykop.pl/link/(.*?)/" title=""',3) For $q = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/link/'&$linki[$q]&@CRLF) Next $linki = StringRegExp($data, 'href="http://www.wykop.pl/ludzie/(.*?)/">',3) ; pobieranie ludzi co dodali znaleziska For $w = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/ludzie/'&$linki[$w]&@CRLF) Next $linki = StringRegExp($data, '<a href="http://www.wykop.pl/ludzie/(.*?)/" title="',3) ; pobieranie ludzi co sa na stronie z mikro For $e = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/ludzie/'&$linki[$e]&@CRLF) Next $linki = StringRegExp($data, '<a class="tag create" href="http://www.wykop.pl/tag/(.*?)/"><em>',3) ; pobieranie ludzi co sa na stronie z mikro For $r = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/tag/'&$linki[$r]&@CRLF) Next $linki = StringRegExp($data, '<class="showTagSummary" href="http://www.wykop.pl/tag/(.*?)">',3) ; pobieranie ludzi co sa na stronie z mikro For $t = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/tag/'&$linki[$t]&@CRLF) Next $linki = StringRegExp($data, 'href="http://www.wykop.pl/ludzie/(.*?)/" title=""',3) ; pobieranie ludzi z znaleziska, komentarze For $a = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/ludzie/'&$linki[$a]&@CRLF) Next $linki = StringRegExp($data, 'href="http://www.wykop.pl/tag/index/(.*?)/"',3) ; pobierane tagi ze znaleziska, For $s = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/tag/index/'&$linki[$s]&@CRLF) Next $linki = StringRegExp($data, '<a class="clearfix" href="http://www.wykop.pl/link/(.*?)/?utm_source',3) ; pobierane znaleziska z prawego menu For $d = 0 To UBound($linki) -1 FileWrite(@ScriptDir&'\data\links.txt','http://www.wykop.pl/link/'&$linki[$d]&@CRLF) Next Sleep(5000) GuiCtrlSetData($Edit2, GuiCtrlRead($Edit2)+1) _FileWriteToLine(@ScriptDir&'\data\links.txt',GuiCtrlRead($edit1),'',1) VisitFrontPage() EndFunc While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 Case $Button2 VisitFrontPage() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd  
  • Create New...