Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/02/2017 in all areas

  1. jchd

    SQLite backup API wrapper

    SQlite error 11 (décimal) is SQLITE_CORRUPT, meaning that the Connection is to a corrupt DB. Page sizes have nothing to do with error 11.
    2 points
  2. 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
  3. Dear AutoIt + SQLite user, I wrote this little function to benefit of the recently introduced SQLite backup API. "Recently" is somehow a distorsion of history, since its first appearance was in version 3.6.11. Q) Is the thing easy to use? A) Yes: there is only one call that takes care of everything (almost). Q) Why should you use it, instead of simply copying the SQLite database file itself? A) There are common siuations where you just can't do that. Either there are other uninterruptible processes using the database, or you managed to build a memory database but at some point decided that it would be wise to avoid loosing your work if ever your fine application crashes :ahem: a power loss occurs! In both cases, you have to be very, very careful duplicating your database as they are many potential pitfalls doing so. Q) So it is possible to keep on reading the source database while it is being backed up?!? A) Exactly. Q) And it is possible to modify the source database during its backup?!? A) Also correct, BUT each time the base is modified, the backup needs to restart, or write again a number of dirty pages. Thus, if you write at high rate to your source base, it's likely that the backup process will never complete. Q) How should you use it? A) Read the fine doc! No, seriously there is no proper documentation, just a short abstract. Q) Is there a runable example to better understand how it works? A) Yes, along the function itself, there is a usable example. Please regard this as a beta: there may remain bugs in it and the interface may change in some future. Don't rely on this for mission-critical data, you've been warned. I'd like to receive your bug reports and suggestions. 2010-01-13 version 0.1 2010-03-14 version 0.2 changed return value to DB handle, so that the function can be used to load a disk-DB into memory EDIT 18/06/2014: fixed new global variable name. SQLitebackup.au3 Little demo in pseudo-real situation: SQLitebackupTest.au3 EDIT: ignore the #include for helpers.au3 in the example.
    1 point
  4. I wanted a timer, could not find what I wanted and wrote this. Posted for the next lazy one, like me, copy'n'paste kind of ppl. And added an "Alarm", ( at times I need it to trigger at a time and not, in so many minutes ) Also added an "insist/replay" ( since I'm coding, might as well have the feature ) #NoTrayIcon #include <TrayConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) ; removes the chance for misspelled variables causing bugs. Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode. Opt("GUIOnEventMode", 1) ; OnEvent functions notifications Global $seconds = 0, $g_sec, $g_min, $g_hr, $started = False, $sec = 99, $aTimeHold[3], $g_IsAlarm = 0, $iAppTitle, $sAppTitle = timerTitle() $iAppTitle = @extended #Region ### START Koda GUI section ### Form=\\WDMYCLOUDEX4100\Public\[FMIS]\au3_Shared_projects\timerThing.kxf Global $Form1 = GUICreate($sAppTitle, 245, 74, @DesktopWidth - 275 - (40 * $iAppTitle), 20 + (40 * $iAppTitle), -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) Global $idHour = GUICtrlCreateInput("00", 5, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idMin = GUICtrlCreateInput("00", 58, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idSec = GUICtrlCreateInput("00", 110, 4, 49, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) Global $idStart = GUICtrlCreateButton("Start Timer", 163, 6, 75, 61, $BS_MULTILINE) Global $idTitle = GUICtrlCreateInput("", 4, 40, 129, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_WANTRETURN)) Global $idAlarm = GUICtrlCreateCheckbox("", 137, 53, 17, 19, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON)) Global $idInsist = GUICtrlCreateCheckbox("", 137, 37, 17, 19, BitOR($GUI_SS_DEFAULT_CHECKBOX, $BS_RIGHTBUTTON)) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetFont($idHour, 14, 800) GUICtrlSetFont($idMin, 14, 800) GUICtrlSetFont($idSec, 14, 800) GUICtrlSetFont($idStart, 12, 800) GUICtrlSetFont($idTitle, 12, 800) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUICtrlSetOnEvent($idStart, "idStartClick") GUICtrlSetOnEvent($idTitle, "idTitleChange") GUICtrlSetOnEvent($idAlarm, "idAlarmEvent") TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "OnTray_PRIMARYDOUBLE") GUICtrlSetTip($idStart, 'press ENTER or click' & @CR & @CR & 'once started, on close,' & @CR & 'will move to the tray area.') GUICtrlSetTip($idHour, 'Hours' & @CR & @CR & 'enter the hours' & @CR & 'and press ENTER') GUICtrlSetTip($idMin, 'Minutes' & @CR & @CR & 'enter the minutes' & @CR & 'and press ENTER') GUICtrlSetTip($idSec, 'Seconds' & @CR & @CR & 'enter the seconds' & @CR & 'and press ENTER') GUICtrlSetTip($idTitle, 'Type a title for this' & @CR & 'timer and press ENTER') GUICtrlSetTip($idAlarm, 'Swap between' & @CR & 'Timer and Alarm' & @CR & 'functionality') GUICtrlSetTip($idInsist, 'Replay the alert' & @CR & 'every 10 sec.' & @CR & 'for 10 min.') ;~ If Not FileGetSize("timerThing.wav") Then FileInstall("timerThing.wav", "timerThing.wav") ; if you wanna include your WAV file Global $hForm1 = WinGetHandle($Form1) Global $idDummy = GUICtrlCreateDummy() Global $aAccelKeys[1][2] = [["{Enter}", $idDummy]] GUISetAccelerators($aAccelKeys) GUICtrlSetOnEvent($idDummy, "On_idDummy") While 1 Sleep(50) If Not $started Then ContinueLoop If $sec = @SEC Then ContinueLoop $sec = @SEC Countdown() WEnd Func Form1Close() If $started Then TraySetState(1) WinSetState($hForm1, "", @SW_HIDE) Else GUIDelete() Exit EndIf EndFunc ;==>Form1Close Func Countdown() ; mod. from https://www.autoitscript.com/forum/topic/135227-simple-counter/?do=findComment&comment=950305 If $g_IsAlarm Then If Int(GUICtrlRead($idHour)) = Int(@HOUR) And Int(GUICtrlRead($idMin)) = Int(@MIN) And Int(GUICtrlRead($idSec)) = Int(@SEC) Then $seconds = -1 Else Return EndIf EndIf $g_sec = Mod($seconds, 60) $g_min = Mod($seconds / 60, 60) $g_hr = Floor($seconds / 60 ^ 2) If $seconds < -3 Then Return TrayToolTip() $seconds -= 1 If $seconds = -2 Then GUICtrlSetState($idInsist, $GUI_DISABLE) If GUICtrlRead($idInsist) = 1 Then $seconds = -5 InsistPlayTheWAV() AdlibRegister("InsistPlayTheWAV", 10000) Else playTheWAV() EndIf Return EndIf If $seconds < -1 Then Return GUICtrlSetData($idHour, StringFormat("%02i", $g_hr)) GUICtrlSetData($idMin, StringFormat("%02i", $g_min)) GUICtrlSetData($idSec, StringFormat("%02i", $g_sec)) EndFunc ;==>Countdown Func playTheWAV() OnTray_PRIMARYDOUBLE() WinActivate($hForm1) If Not FileGetSize(@ScriptDir & "\timerThing.wav") Then SoundSetWaveVolume(25) SoundPlay(@WindowsDir & "\media\tada.wav") Else SoundSetWaveVolume(5) SoundPlay(@ScriptDir & "\timerThing.wav") EndIf EndFunc ;==>playTheWAV Func InsistPlayTheWAV() Local Static $t = 0 If $t = 0 Then $t = TimerInit() playTheWAV() If TimerDiff($t) > 600000 Then AdlibUnRegister("InsistPlayTheWAV") $t = 0 EndIf EndFunc ;==>InsistPlayTheWAV Func TrayToolTip() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) TraySetToolTip('' & _ $title & @CR & _ GUICtrlRead($idHour) & ":" & GUICtrlRead($idMin) & ":" & GUICtrlRead($idSec) & @CR & @CR & _ 'Double' & @CR & _ 'Click to' & @CR & _ 'restore' & @CR & @CR & ' ') EndFunc ;==>TrayToolTip Func idStartClick() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) WinSetTitle($hForm1, "", $title) $sec = 99 $started = Not $started Switch $started Case True GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Start", "STOP")) $seconds = (Int(GUICtrlRead($idHour)) * 60 * 60) + (Int(GUICtrlRead($idMin)) * 60) + Int(GUICtrlRead($idSec)) $aTimeHold[0] = StringFormat("%02i", GUICtrlRead($idHour)) $aTimeHold[1] = StringFormat("%02i", GUICtrlRead($idMin)) $aTimeHold[2] = StringFormat("%02i", GUICtrlRead($idSec)) GUICtrlSetState($idStart, $GUI_FOCUS) GUICtrlSetState($idHour, $GUI_DISABLE) GUICtrlSetState($idMin, $GUI_DISABLE) GUICtrlSetState($idSec, $GUI_DISABLE) GUICtrlSetState($idAlarm, $GUI_DISABLE) Case Else GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "STOP", "Start")) GUICtrlSetData($idHour, $aTimeHold[0]) GUICtrlSetData($idMin, $aTimeHold[1]) GUICtrlSetData($idSec, $aTimeHold[2]) GUICtrlSetState($idHour, $GUI_ENABLE) GUICtrlSetState($idMin, $GUI_ENABLE) GUICtrlSetState($idSec, $GUI_ENABLE) GUICtrlSetState($idAlarm, $GUI_ENABLE) GUICtrlSetState($idInsist, $GUI_ENABLE) GUICtrlSetState($idStart, $GUI_FOCUS) EndSwitch EndFunc ;==>idStartClick Func On_idDummy() Local $i, $s = ControlGetFocus($hForm1) $i = Int(StringRight($s, 1)) If $s = "Button1" Then Return ControlClick($hForm1, "", "Button1") If StringInStr($s, "Edit") Then Switch $i Case 1, 2, 3 Send("{Tab}") EndSwitch EndIf EndFunc ;==>On_idDummy Func idTitleChange() Local $title = $sAppTitle If GUICtrlRead($idTitle) Then $title = GUICtrlRead($idTitle) WinSetTitle($hForm1, "", $title) EndFunc ;==>idTitleChange Func timerTitle() Local $n, $i = 0 For $n = 1 To 1000 If Not WinExists(" Timer thing [" & $n & "]") Then AutoItWinSetTitle(" Timer thing [" & $n & "]") $i = $n - 1 If 40 * $n > @DesktopHeight - 150 Then $i = 1 Return SetError(0, $i, " Timer " & $n) EndIf Next Return SetError(1, $i, " Timer ???") EndFunc ;==>timerTitle Func OnTray_PRIMARYDOUBLE() TraySetState(2) WinSetState($hForm1, "", @SW_SHOW) EndFunc ;==>OnTray_PRIMARYDOUBLE Func idAlarmEvent() ConsoleWrite('+ Func idAlarmEvent() : ' & GUICtrlRead($idAlarm) & @CRLF) If GUICtrlRead($idAlarm) = 1 Then $g_IsAlarm = 1 GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Timer", "Alarm")) $sAppTitle = StringReplace($sAppTitle, "Timer", "Alarm") Else $g_IsAlarm = 0 GUICtrlSetData($idStart, StringReplace(GUICtrlRead($idStart), "Alarm", "Timer")) $sAppTitle = StringReplace($sAppTitle, "Alarm", "Timer") EndIf idTitleChange() EndFunc ;==>idAlarmEvent
    1 point
  5. Nice new article published in microsoft docs on dynamicbject. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/walkthrough-creating-and-using-dynamic-objects Will try after my holiday
    1 point
  6. Hi, @Deye! Actually what you are trying to do is to create a HTTP server. Note that this UDF supports TCP protocol in a generic state. This means that while you can of course create a HTTP server with it, you will not find everything ready to use as it just takes care about the network part. Sending the form is as easy as: https://github.com/jesobreira/TCPServerUDF/blob/master/example HTTP Server.au3#L20 (notice the HTML on the lines 20-23). However for parsing the user request as well as form data, you will need to handle and parse the HTTP headers sent by the browser. It's not something so hard to understand, but depending on what you want to offer, it's a bite of work. Basically it's just string parsing, nothing that you won't solve with a few StringSplit()s, comparisons and regexp - but a lot of them. If you want to create a full-featured webserver (good luck!), I suggest you to read the HTTP specs: https://www.w3.org/Protocols/Specs.html If what you want is something simple, I suggest you to use Chrome Dev Tools (Ctrl + Shift + J), go to "Network" tab and get familiarized with the HTTP headers sent and received by the browser. You'll see that it's not hard at all. Using a sniffer (Smartsniff or Socketsniff, or even Wireshark although it might be too advanced for simple analysis) against your browser is also very learningful; you can see how the headers and HTML are sent. If you need any further help feel free to comment on this thread!
    1 point
  7. ... and you are sure you couldn't find this on the internet with a simple Google search? Jos
    1 point
×
×
  • Create New...