Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/02/2016 in all areas

  1. FredAI

    Set Acl permissions UDF

    Hi. I've been working on this for a while. I think now it's good enough to post it here. Functions to do most everything with the DACL and ownership on all types of objects: Files or folders, Registry keys, services, Kernel and WMI objects, etc. Here's a good example to test: #include 'Permissions.au3' _InitiatePermissionResources() FileWrite(@ScriptDir&'test.txt','Test') Local $TI = TimerInit() Local $ret = _DenyAllAccess(@ScriptDir&'test.txt',$SE_FILE_OBJECT,@UserName) Local $TD = TimerDiff($TI) MsgBox(0,'','Deny all access to test.txt and take ownership:'&@CRLF&@CRLF& _ '_DenyAllAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _GrantReadAccess(@ScriptDir&'test.txt',$SE_FILE_OBJECT,'Administrators') $TD = TimerDiff($TI) MsgBox(0,'','Grant everyone read access, all access to admins and system, and set the owner: Admins group'&@CRLF&@CRLF& _ '_GrantReadAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _GrantAllAccess(@ScriptDir&'test.txt') $TD = TimerDiff($TI) MsgBox(0,'','Grant everyone access'&@CRLF&@CRLF& _ '_GrantAllAccesss return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() $ret = _CopyFullDacl(@ScriptDir&'test.txt',$SE_FILE_OBJECT,@ScriptDir) $TD = TimerDiff($TI) MsgBox(0,'','Restore all inherited permissions'&@CRLF&@CRLF& _ '_CopyFullDacl return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Local $aPerm[2][3] = [['Restricted',1,$GENERIC_ALL],['Users',1,$GENERIC_ALL]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Add two granted access aces: Restricted and Users'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Dim $aPerm[2][3] = [['Restricted',1,$GENERIC_READ],['Users',1,$GENERIC_READ]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Give only read access to the Restricted and Users groups'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Dim $aPerm[2][3] = [['Restricted',0,$GENERIC_ALL],['Users',0,$GENERIC_ALL]] $ret = _EditObjectPermissions(@ScriptDir&'test.txt',$aPerm) $TD = TimerDiff($TI) MsgBox(0,'','Deny access to the Restricted and Users groups'&@CRLF&@CRLF& _ '_EditObjectPermissions return value: '&$ret&' Time: '&Round($TD,2)&' miliseconds.'&@CRLF& _ 'Check the file permissons before closing the message box.') $TI = TimerInit() Local $Hndl = _Permissions_OpenProcess(@AutoItPID) Local $SDBefore = _GetObjectStringSecurityDescriptor($Hndl,$SE_KERNEL_OBJECT) Local $CODRet = _ClearObjectDacl($Hndl,$SE_KERNEL_OBJECT) Local $DARet = _DenyAllAccess($Hndl,$SE_KERNEL_OBJECT) Local $SDAfter = _GetObjectStringSecurityDescriptor($Hndl,$SE_KERNEL_OBJECT) $TD = Round(TimerDiff($TI),2) MsgBox(0,'', 'Deny everyone access to the current process:'&@CRLF&@CRLF& _ '@AutoItPID original security descriptor: '&@CRLF&$SDBefore&@CRLF&@CRLF& _ '_ClearObjectDacl return value: '&$CODRet&@CRLF&@CRLF& _ '_DenyAllAccess_ return value: '&$DARet&@CRLF&@CRLF& _ 'New @AutoItPID security descriptor: '&@CRLF& _ $SDAfter&@CRLF&@CRLF& 'Time taken: '&$TD&' miliseconds.') _Permissions_CloseHandle($Hndl) FileDelete(@ScriptDir&'test.txt') _ClosePermissionResources()I'm planning to add functions to deal with the Sacl in the future, even though I don't think it's very important. Edit: Let me know if you need an example for the registry. Updated: Fixed a bug in the _ClearObjectDacl function. I thought that adding a null DACL would work fine, but it causes problems later when adding a new DACL. Those who have downloaded, please update. Shoot! Now it wasn't clearing the DACL at all. Updated again. I think it's fixed now. Updated 9/11/2011 - Added the security descriptor functions and removed unnecessary constants. Updated 10/11/2011 - There were some functions missing in the index, and some parameters in the comments. Also removed the "MustDeclareVars" option. (About 50 total downloads before) Update 12/12/2011 - Added more functions: New Update 12/12/2011 - Missing declaration keywords in 3 constants. Sorry Update 16/12/2011 - Added support for all object types, including window and process handles. Added more functions, modified most of them, and removed one. Here's the new function list: Updated 22/2/2012.. This time I'm including SecurityConstants.au3 and FileConstants.au3 to prevent constants conflicts. Added a few more functions and fixed a few bugs. Also added the ability to include the inherited aces in the _EditObjectPermissions function. Now the permissions array can have four elements (optional). It will still work with three elements arrays though. The fourth element is intended to have the inheritance flag for the corresponding ace. Here's the new list of functions: 400 previous downloads Permissions.au3
    1 point
  2. Hello! Here is a short example to get the notification when the monitors are going to sleep. Have fun! #NoTrayIcon Global Const $WM_POWERBROADCAST = 0x0218 Global Const $PBT_POWERSETTINGCHANGE = 0x8013 Global Const $WM_SYSCOMMAND = 0x0112 Global Const $SC_MONITORPOWER = 0xF170 Global Const $MONITOR_ON = -1 Global Const $MONITOR_OFF = 2 Global Const $MONITOR_STANDBY = 1 Global Const $tagGUID = "struct; ulong Data1;ushort Data2;ushort Data3;byte Data4[8]; endstruct" Global Const $tagPOWERBROADCAST_SETTING = $tagGUID & ";DWORD DataLength;DWORD Data;" Global Const $DEVICE_NOTIFY_WINDOW_HANDLE = 0 Global Const $DEVICE_NOTIFY_SERVICE_HANDLE = 1 Global Const $GUID_CONSOLE_DISPLAY_STATE = "{6fe69556-704a-47a0-8f24-c28d936fda47}" ; Win8 Global Const $GUID_MONITOR_POWER_ON = "{02731015-4510-4526-99e6-e5a17ebd1aea}" ; Vista and Win7 Global $hGui = GUICreate("Gui for registering Windows Message", 600, 400) GUIRegisterMsg($WM_POWERBROADCAST, "_PowerSettingNotification") Global $nBtnSleep = GUICtrlCreateButton("Hey monitors, please sleep!", 50, 50, 500, 100) GUICtrlSetFont(-1, 25) Global $nEdit = GUICtrlCreateEdit("Informations:", 50, 180, 500, 200, 0x200840) ;$WS_VSCROLL | $ES_AUTOVSCROLL | $ES_READONLY GUICtrlSetFont(-1, 14) Global $hNotify If @OSBuild >= 5000 And @OSBuild < 9000 Then $hNotify = _RegisterPowerSettingNotification($hGui, $GUID_MONITOR_POWER_ON) ElseIf @OSBuild >= 9000 Then $hNotify = _RegisterPowerSettingNotification($hGui, $GUID_CONSOLE_DISPLAY_STATE) Else MsgBox(64, "Sorry", "PowerSettingNotification is only supported by Windows Vista and above!") Exit EndIf If @error Then MsgBox(16, "Sorry", "PowerSettingNotification failed with error: " & @error & " - " & @extended & " !") Exit EndIf GUISetState() Global $iMsg Do $iMsg = GUIGetMsg() If $iMsg = $nBtnSleep Then DllCall('user32.dll', 'int', 'SendMessage', 'hwnd', $hGui, 'int', $WM_SYSCOMMAND, 'int', $SC_MONITORPOWER, 'int', $MONITOR_OFF) Until $iMsg = -3 _UnregisterPowerSettingNotification($hNotify) Func _PowerSettingNotification($hWndGUI, $MsgID, $wParam, $lParam) Local $tSetting, $iSetting Local $sDateNow, $sTimeNow, $sMsg If $wParam = $PBT_POWERSETTINGCHANGE Then $tSetting = DllStructCreate($tagPOWERBROADCAST_SETTING, $lParam) $iSetting = DllStructGetData($tSetting, "Data") $sDateNow = @YEAR & "-" & @MON & "-" & @MDAY $sTimeNow = @HOUR & ":" & @MIN & ":" & @SEC Switch $iSetting Case 2 ;The display is dimmed --> Win8 and above $sMsg = $sDateNow & " " & $sTimeNow & " : " & "The display is dimmed now" ConsoleWrite("> " & $sMsg & @CRLF) GUICtrlSetData($nEdit, GUICtrlRead($nEdit) & @CRLF & $sMsg) ;do some stuff here Case 1 ;The monitor in on $sMsg = $sDateNow & " " & $sTimeNow & " : " & "The display is on now" ConsoleWrite("> " & $sMsg & @CRLF) GUICtrlSetData($nEdit, GUICtrlRead($nEdit) & @CRLF & $sMsg) ;do some stuff here Case 0 ;The monitor in off $sMsg = $sDateNow & " " & $sTimeNow & " : " & "The display is off now" ConsoleWrite("> " & $sMsg & @CRLF) GUICtrlSetData($nEdit, GUICtrlRead($nEdit) & @CRLF & $sMsg) ;do some stuff here EndSwitch EndIf EndFunc ;==>_PowerSettingNotification Func _RegisterPowerSettingNotification($hGui, $GUID) Local $aRet Local $tGuid = DllStructCreate($tagGUID) $aRet = DllCall('ole32.dll', 'long', 'CLSIDFromString', 'wstr', $GUID, 'struct*', $tGuid) If @error Or $aRet[0] <> 0 Then Return SetError(1, @error, 0) $aRet = DllCall("user32.dll", "handle", "RegisterPowerSettingNotification", "handle", $hGui, "struct*", $tGuid, "DWORD", $DEVICE_NOTIFY_WINDOW_HANDLE) If @error Or $aRet[0] = 0 Then Return SetError(2, @error, 0) Return $aRet[0] EndFunc ;==>_RegisterPowerSettingNotification Func _UnregisterPowerSettingNotification($hNotify) Local $aRet = DllCall("user32.dll", "BOOL", "UnregisterPowerSettingNotification", "handle", $hNotify) If @error Or $aRet[0] = 0 Then Return SetError(1, @error, 0) Return $aRet[0] EndFunc ;==>_UnregisterPowerSettingNotification
    1 point
  3. The best optimization by far would be to use Scripting.Dictionary #include <Array.au3> local $BlackList = ["xxx", "yyy", "zzz"] local $OldFoundMatchesUsernames = ["aaa", "bbb", "ccc", "ddd"] local $FoundMatchesUsernames = ["yyy", "ggg", "aaa", "eee", "xxx", "ddd", "ccc", "zzz", "fff"] ; create dictionary Local $sdFoundMatchesUsernames = ObjCreate("Scripting.Dictionary") ; $sdFoundMatchesUsernames.CompareMode = 1 ; case insensitive (if needed) ; build the dictionary (removing duplicates) For $i In $FoundMatchesUsernames $sdFoundMatchesUsernames.Item($i) Next ; remove blacklisted For $i In $BlackList $sdFoundMatchesUsernames.Remove($i) Next ; add $OldFoundMatchesUsernames (this also removes duplicates) For $i In $OldFoundMatchesUsernames $sdFoundMatchesUsernames.Item($i) Next ; get new $FoundMatchesUsernames array $FoundMatchesUsernames = $sdFoundMatchesUsernames.Keys() _ArraySort($FoundMatchesUsernames) _ArrayDisplay($FoundMatchesUsernames, "$FoundMatchesUsernames") Edit Comments added
    1 point
  4. If you are working with large arrays, you may want to consider my solution for optimization purposes.
    1 point
  5. trancexx

    A naive question

    First case: x = 100 y = ++x * 2 yields: x = 101 y = 202 ... whereas second one: x = 100 y = x++ * 2 yields: x = 101 y = 200
    1 point
  6. mLipok

    A naive question

    hmmm....... Maybe like this: if ($r > $x Or $err > $y) Then $x += 1 $err += $x*2+1 EndIf
    1 point
  7. For $i = UBound($FoundMatchesUsernames) - 1 To 0 Step -1 ;<< loop to 0
    1 point
  8. Because of the operators precedence, this If Not $OldFoundMatchesUsernames[0] == "Empty" Then is evaluated like this If (Not $OldFoundMatchesUsernames[0]) == "Empty" Then so it should (probably...) be written like this If Not ($OldFoundMatchesUsernames[0] == "Empty") Then
    1 point
  9. Wouldn't it be easier and faster to lose the for next loop entirely and replace it with these 2 lines of code: _ArrayAdd($FoundMatchesUsernames,$OldFoundMatchesUsernames);combines the 2 arrays into 1. $FoundMatchesUsernames=_ArrayUnique($FoundMatchesUsernames);Uniques the array.
    1 point
  10. https://www.autoitscript.com/wiki/User_Defined_Functions#Browsers
    1 point
  11. Have you tried searching the forums and google? Something tells me you haven't. Most people aren't going to work for free if you aren't going to put in at least a little bit of effort.
    1 point
  12. Update debugger: Changed interface. Fixed detected the errors. Others improvements and additions. Dbug_2016.02.18.zip
    1 point
  13. I just got it to work! I was having much trouble, reading all the threads and posts related to ImageSearch, and I'd like to help others now. Now got it to work as a x64 and also as a x32 script using both DLLs accordingly (on a Windows 8.1 x64 PC) One of the steps I took in debugging was putting this into (the top of) my script: $sOSArch = @OSArch ;Check if running on x64 or x32 Windows ;@OSArch Returns one of the following: "X86", "IA64", "X64" - this is the architecture type of the currently running operating system. ConsoleWrite("$sOSArch=" & $sOSArch & @CR) $sAutoItX64 = @AutoItX64 ;Check if using x64 AutoIt ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt. ConsoleWrite("$sAutoItX64=" & $sAutoItX64 & @CR)In any case you want to be consistent about 32bit or 64bit usage, and use the right DLL etc. What also really helped was putting in lots of debugging and error handling to zoom in on whatever specific part isn't working and why. Credits to Centrally (very helpful usage explanation and re-uploading the files) and kangkeng for making this possible in AutoIt, as well Miguel7 from the AutoHotKey forum who also posted some helpful advice. I've attached a zipped folder containing all of the needed Dlls and my customised Library, which also contains an example and some debugging: ImageSearch2015.zip Take a look inside ImageSearch2015.au3 here if you like: Edit: also uploaded "ImageSearch15.au3", a version of "my" ImageSearch Library without the built-in Example and Debugging (will require the Dlls in the .zip file though): ImageSearch15.au3 I hope this helps somebody! Let me know any feedback/issues.
    1 point
×
×
  • Create New...