Foxnolds Posted July 30, 2006 Share Posted July 30, 2006 (edited) UnAttended Event Handler v0.1.2.0UnAttended_v0_1_2_0.zip - Full kit including UDFs below.I've spent a couple of weeks now playing with AutoIt v3 Beta 3.1.1.127-132 and this was the first project I wrote for myself to learn the ropes. If you don't find the UnAttended application useful then you may like the couple of potential UDFs I had to write to do stuff I needed: MsgBoxEx.au3 MsgBoxEx.zipDriveGetDriveEx.au3 DriveGetDriveEx.zipSysTray.au3 - My fixed version for my needs SysTray.zipWhat is it? UnAttended is an AutoIt3 Script that watches for dialogs and fills them in or dismisses them automatically - particularly when you are away from your computer.It will fill in passwords for Jetico BestCrypt encrypted Volumes, PGP Disks and PGP Identities, Windows Network Mounted Shares mounted under different user Domain names and Launch Putty SSH sessions as well as a DOS Command Shell as required.It monitors Crashing Dialogs from Eudora Email Application (Usually due to some bad spam *.CRV file in the Spool directory, crashing dialogs from Microsoft ActiveSync 4.x and various other Windows Mobile Pocket PC Applications.It knows about a VPN connection from Home to Work and uses it to mount Work Network drives as required.UnAttended will also act as a PC Lock, Locking the Screen and turning off the monitor when a registered USB Device (USB Key Disk) or an ActiveSync USB/Bluetooth connection leaves. Known Problems:I have not had success in catching Windows Session Close. The problem this causes is that UnAttended may be closed too early, or it may try to restore a Closed Eudora Application if it has seen the Session Quit message before UnAttended.Not all error dialogs and conditions have been caught and identified. Hopefully this will improve over time. I may have addressed this issue with the User Dialogs Configuration Tab.Launching a VPN connection is clumsy. I need to find a better method than launching a .LNK file.Polling status of disconnected Network drives can be time consuming. It can take upto 25 seconds of a blocking call to determine that a Network drive is no longer available. VPN status is only polled once per minute now.Polling the status of a SysTrayIcon that is no longer present is also slow. Again, it can take a few seconds to realise that the Application is not running any more. For example the VPN connection status is read from its SysTrayIcon.I'm sure there's more....I whipped up the start of a help file that I'll post next. I still need to learn how to hook it into an AutoIt application.. Edit: 1st Aug 06 - Changed VPN detection to use "RASDial" technique. Thanks flyingboz.- Sped up disconnected Network drive handling by using "Net Use" command.Edit - Added some screen shots.. Edited July 31, 2006 by Foxnolds My UnAttended Event Handler , MsgBoxEx , DriveGetDriveEx and SysTray modified. Link to comment Share on other sites More sharing options...
Foxnolds Posted July 30, 2006 Author Share Posted July 30, 2006 Here is the Help.chm file I built - also trying to learn Vizacc HelpMaker.. UnAttended_Help_v0_1_1_0.zip UnAttended Event Handler v0.1.1.0 I whipped up the start of a help file that I'll post next. I still need to learn how to hook it into an AutoIt application.. : " /> My UnAttended Event Handler , MsgBoxEx , DriveGetDriveEx and SysTray modified. Link to comment Share on other sites More sharing options...
flyingboz Posted July 30, 2006 Share Posted July 30, 2006 [*]Launching a VPN connection is clumsy. I need to find a better method than launching a .LNK file.Use the command line tool RASDIAL, i.e. RASDIAL "my connection at work" and RASDIAL "my connection at work" /disconnect errorlevels, etc. are supported for branching / error checking. Excellent when paired or wrapped w/ RunWait(). Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
Foxnolds Posted July 30, 2006 Author Share Posted July 30, 2006 Brilliant! flyingboz!I tried it on my PC and it works a treat.It's 3:50 AM so I must get 3 hours sleep B4 I go to work. I'll plug in the change tonight (Aussie Time) when I get home again... Use the command line tool RASDIAL, i.e. RASDIAL "my connection at work" and RASDIAL "my connection at work" /disconnecterrorlevels, etc. are supported for branching / error checking. Excellent when paired or wrapped w/ RunWait(). My UnAttended Event Handler , MsgBoxEx , DriveGetDriveEx and SysTray modified. Link to comment Share on other sites More sharing options...
Foxnolds Posted July 31, 2006 Author Share Posted July 31, 2006 Here is a snapshot of my MsgBoxEx in action.The MsgBoxEx UDF and a simple Test example.MsgBoxEx.zip The Extentsion to the normal old MsgBox is that it:-Will add Count-down text to the default buttonWill replace the characters <##> with the current remaining number of seconds on upto 5 lines of textWill BOLD a while line of text if <b> or </B> tags are seen on any message line.Accepts optional Parent window parameter so when parent minimises, closes then so does MsgBoxEx dialog.Supports Minimize and Close SysMenu buutonsWorks as a drop-in Modal like replacement for MsgBox() but can also work modeless in your own EventLoop environment. Button action generate Callbacks to your event handler.The 1 to 3 buttons can be of ANY text by an optional Array of button text and button count values.Special Return Codes for Type 8 buttons - PC Lock/Cancel.Too much.. so here's the Function comment section...(Sorry about mangled formatting - Best Grab the zip file above) P.S. The best Parent Window examples of MsgBoxEx use is on the About Dialog Test Button actions in UnAttended Script at the beginning of this post.. expandcollapse popup;=============================================================================== ; +++ This is to emulate a Modal MsgBox($iFlag, $sTitle, $sText [, $iTimeout]) +++ ; _MsgBoxEx($iFlag, $sTitle, $sText [, $iTimeout [, $sReturnCallBack [, $iLeft [, $iTop [, $hParent]]]]]) ; +++ This is the call to use if you have your own EventLoop where you call _MBEX_TickTock() +++ ; _MsgBoxExCreate($iFlag, $sTitle, $sText [, $iTimeout [, $sReturnCallBack [, $iLeft [, $iTop [, $hParent]]]]]) ; ____________________________________________________________________________________________________ ______________ ; $iFlag The flag indicates the type of message box and the possible button combinations. See remarks. ; $sTitle The title of the message box. ; $sText The text of the message box. "<b>" and/or "</b>" will Bold Text of whole Line only. ; Upto 5 lines may have <##> text replaced with the current second countdown value. ; $iTimeout [optional] Timeout in seconds. After the timeout has elapsed the message box will be closed. ; Default value of 0 will disable timeout. ; $sReturnCallBack [optional] The name of a function you provide that takes a single argument, the ReturnCode. ; Default value is Null String "" which is replaced with internal handler when ; _MsgBoxEx() funcion called. ; If using _MsgBoxExCreate(), ; you MUST register your own ReturnCallBack function here... ; And in your Event Loop, you need to call _MBEX_TickTock() to update timers. ; $iLeft [optional] X Position of Dialog, default of -1 centers dialog horizontally. ; $iTop [optional] Y Position of Dialog, default of -1 centers dialog vertically. ; $hParent [optional] Handle to a Parent Window, defaults to 0. ; ____________________________________________________________________________________________________ ______________ ; ; Note, as this is Modeless, this version does not support multiple instances which can be invoked. ; The code uses the Dialog handle of non-zero to test if another is running already. ; ; Failure: Returns -1 if the message box timed out. ; ; Button Pressed Return Value sent to $gsMBEX_CallBack function you provide ; OK 1 ; CANCEL 2 ; ABORT 3 ; RETRY 4 ; IGNORE 5 ; YES 6 ; NO 7 ; TRY AGAIN ** 10 ; CONTINUE ** 11 ; LOCK PC 12 - You have to do the locking... ; CLOSE 13 - New Return code ; _____________________________________________________________________ ; ; The flag parameter can be a combination of the following values: ; ; decimal flag Button-related Result hexadecimal flag ; 0 OK button 0x0 ; 1 OK and Cancel 0x1 ; 2 Abort, Retry, and Ignore 0x2 ; 3 Yes, No, and Cancel 0x3 ; 4 Yes and No 0x4 ; 5 Retry and Cancel 0x5 ; 6 ** Cancel, Try Again, Continue 0x6 ; 7 ++ +++ See Note7 +++ 0x7 ; 8 ++ Lock PC, Cancel 0x8 ; ; +++ Note7 +++ User sets the Global Array Variables Before Calling this Function ; $gaMBEX_BT[0] = 1, 2 or 3 ; $gaMBEX_BT[1] = "Left Button" ; $gaMBEX_BT[2] = "Right Button" ; $gaMBEX_BT[3] = "Middle Button" ; _____________________________________________________________________ ; decimal flag Icon-related Result hexadecimal flag ; 0 (No icon) 0x0 ; 16 Stop-sign icon 0x10 ; 32 Question-mark icon 0x20 ; 48 Exclamation-point icon 0x30 ; 64 Information-sign icon consisting of an 'i' in a circle 0x40 ; _____________________________________________________________________ ; decimal flag Default-related Result hexadecimal flag ; 0 First button is default button 0x0 ; 256 Second button is default button 0x100 ; 512 Third button is default button 0x200 ; 1024 +++ Default Button has CountDown text 0x400 ; _____________________________________________________________________ ; decimal flag Modality-related Result hexadecimal flag ; 0 Application 0x0 ; 4096 ++ System modal (dialog has an icon) 0x1000 ; 8192 -- Task modal - Not supported 0x2000 ; _____________________________________________________________________ ; decimal flag Miscellaneous-related Result hexadecimal flag ; 0 (nothing else special) 0x0 ; 262144 MsgBox has top-most attribute set 0x40000 ; 524288 -- title and text are right-justified 0x80000 ; ; ** was Only valid on Windows 2000/XP and above. ; ________________________________________________________________ ; ;=============================================================================== Here is the MsgBoxExTest.au3 Code:expandcollapse popup; ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.1.1.131+ ; Language: English ; Description: Test Alternative to MsgBox() with extended functionality. ; Author(s): Foxnolds <foxnolds at ewise dot com> ; ------------------------------------------------------------------------------ ;=============================================================================== ; Test routine for MsgBoxEx_UDF.au3 ;=============================================================================== Global $gbDoEventLoop, $ghMsgDlg Local $ls, $liRtnVal Opt("MustDeclareVars", 1) ;0=no (default), 1=require pre-declare ; Include the Animated MsgBox Modeless code #include "MsgBoxEx.au3" ; Test Buttons $ls = "<b>Flag=0 + 1024" & @lf & "Test 1 - OK button" & @LF & "Default button wil be clicked in <##> seconds" $liRtnVal = _MsgBoxEx(0 + 1024, "Test Buttons 1", $ls, 30) $ls = "<b>Flag=1" & @lf & "Test 2 - OK and Cancel" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 1 result was " & $liRtnVal $ls &= @LF & @LF & "<b>Press Cancel to skip the rest of the display tests</b>" $liRtnVal = _MsgBoxEx(1, "Test Buttons 2", $ls, 30) IF $liRtnVal == 1 Then $ls = "<b>Flag=2 + 1024" & @lf & "Test 3 - Abort, Retry, and Ignore" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 2 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(2 + 1024, "Test Buttons 3", $ls, 30) $ls = "<b>Flag=3" & @lf & "Test 4 - Yes, No, and Cancel" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 3 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(3, "Test Buttons 4", $ls, 30) $ls = "<b>Flag=4" & @lf & "Test 5 - Yes and No" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 4 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(4, "Test Buttons 5", $ls, 30) $ls = "<b>Flag=5 + 1024" & @lf & "Test 6 - Retry and Cancel" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 5 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(5 + 1024, "Test Buttons 6", $ls, 30) $ls = "<b>Flag=6" & @lf & "Test 7 - Cancel, Try Again, Continue" & @LF & "Default button wil be clicked in <##> seconds" & @LF & "Test 6 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(6, "Test Buttons 7", $ls, 30) $gaMBEX_BT[0] = 3 $gaMBEX_BT[1] = "Button1" $gaMBEX_BT[2] = "Button2" $gaMBEX_BT[3] = "Middle" $ls = "<b>Flag=7 + 1024" & @lf & "Test 8 - Button1, Middle, Button2" & @LF & "Test 7 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(7 + 1024, "Test Buttons 7", $ls, 30) $gaMBEX_BT[0] = 2 $gaMBEX_BT[1] = "Button1" $gaMBEX_BT[2] = "Button2" $gaMBEX_BT[3] = "" $ls = "<b>Flag=7" & @lf & "Test 8 - Button 1 and 2 only" & @LF & "Test 7 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(7, "Test Buttons 7", $ls, 30) $gaMBEX_BT[0] = 1 $gaMBEX_BT[1] = "My Custom Button Text" $gaMBEX_BT[2] = "" $gaMBEX_BT[3] = "" $ls = "<b>Flag=7 + 1024" & @lf & "Test 8 - Custom Button Text" & @LF & "Test 7 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(7 + 1024, "Test Buttons 7", $ls, 30) $ls = "<b>Flag=8+256+1024" & @lf & "Test 9 - Lock PC, Cancel" & @LF & "Test 8 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(8+256+1024, "Test Buttons 8", $ls, 30) If $liRtnVal == 12 Then _LockWorkStation(); GotCha! Ha ha ; Test Icons $ls = "<b>Flag=16 Stop-sign" & @lf & "Test 9 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1 + 16, "Test Icon 16", $ls, 30) $ls = "<b>Flag=32 Question-mark" & @lf & "Test Icon 16 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1 + 32, "Test Icon 32", $ls, 30) $ls = "<b>Flag=48+4096 Exclamation-point" & @lf & "Test Icon 32 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1 + 48+4096, "Test Icon 48", $ls, 30) $ls = "<b>Flag=64+1024+4096+524288 Information-sign" & @lf & "Test Icon 48 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1+64+1024+4096+524288, "Test Icon 64", $ls, 30) ; Test Second Default 256 $ls = "<b>Flag=1 + 256" & @lf & "Test Def2 - OK and Cancel" & @LF & "Test Icon 64 result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1 + 256, "Test Default 2", $ls, 30) $ls = "<b>Flag=2 + 256" & @lf & "Test Def2 - Abort, Retry, and Ignore" & @LF & "Previous Test result was " & $liRtnVal $liRtnVal = _MsgBoxEx(2 + 256, "Test Default 2", $ls, 30) $ls = "<b>Flag=0 + 256" & @lf & "Test Def2 - OK" & @LF & "Previous Test result was " & $liRtnVal $liRtnVal = _MsgBoxEx(0 + 256, "Test Default 2", $ls, 30) ; Test Third Default 512 $ls = "<b>Flag=2 + 512" & @lf & "Test Def3 - Abort, Retry, and Ignore" & @LF & "Previous Test result was " & $liRtnVal $liRtnVal = _MsgBoxEx(2 + 512, "Test Default 3", $ls, 30) $ls = "<b>Flag=1 + 512" & @lf & "Test Def3 - OK and Cancel" & @LF & "Previous Test result was " & $liRtnVal $liRtnVal = _MsgBoxEx(1 + 512, "Test Default 3", $ls, 30) $ls = "<b>Flag=0 + 512" & @lf & "Test Def3 - OK" & @LF & "Previous Test result was " & $liRtnVal $liRtnVal = _MsgBoxEx(0 + 512, "Test Default 3", $ls, 30) EndIf ; ; ; ; Now show Event Mode call $ls = "<b>Flag=8+1024+4096" & @LF & "Default button wil be clicked in <##> seconds" & @lf & "Last Test result was " & $liRtnVal $ls &= @LF & @LF & "Timeout OR Left Button will do stated action" & @LF & "Cancel will present another Dialog Before Exiting" $ls &= @LF & "<b>Close box will do immediate Exit<b>" ; _MsgBoxExCreate($iFlag, $sTitle, $sText [, $iTimeout [, $sReturnCallBack [, $iLeft [, $iTop [, $hParent]]]]]) _MsgBoxExCreate(8+1024+4096, "Tests Finished", $ls, 30, "_TestLocalCallBack") _MyLocalEventLoop() Exit ;=============================================================================== ;=============================================================================== Func _MyLocalEventLoop() Local $liValue $gbDoEventLoop = True While $gbDoEventLoop Sleep(1000); Use 1 second delay in Loop so set UseInternalTimer to False in _MBEX_TickTock _MBEX_TickTock(False); Internally, _MBEX_TickTock() tests existance of $ghMBEX anyway WEnd EndFunc;==>_MyLocalEventLoop ;=============================================================================== ;=============================================================================== Func _TestLocalCallBack($piReturnVal) ; Do what you need to do with result.. Switch $piReturnVal Case 12; Lock PC ContinueCase Case -1; Timeout _LockWorkStation() $gbDoEventLoop = False Case 13; Close - Exit your event loop with optional cleanup $gbDoEventLoop = False Case 2; Cancel MsgBox(0, "Result Dlg", "Canceled out within time", 10) $gbDoEventLoop = False EndSwitch EndFunc;==>_TestLocalCallBack ;=============================================================================== ;=============================================================================== Func _LockWorkStation() DllCall("user32.dll", "int", "LockWorkStation") _MonitorOff(True); 1=off, 0=On EndFunc;==>_LockWorkStation ;=============================================================================== ; Function to turn the Monitor on - off ;=============================================================================== Func _MonitorOff($piOff = True) Local $liPrevOpt, $lhWND Local Const $lciWM_SYSCommand = 274 Local Const $lciSC_MonitorPower = 61808 Local Const $lciPower_Off = 2 Local Const $lciPower_On = -1 $liPrevOpt = Opt("WinTitleMatchMode", 4) $lhWND = WinGetHandle("classname=Progman") If $piOff Then DllCall("user32.dll", "int", "SendMessage", "hwnd", $lhWND, "int", $lciWM_SYSCommand, _ "int", $lciSC_MonitorPower, "int", $lciPower_Off) Else DllCall("user32.dll", "int", "SendMessage", "hwnd", $lhWND, "int", $lciWM_SYSCommand, _ "int", $lciSC_MonitorPower, "int", $lciPower_On) EndIf Opt("WinTitleMatchMode", $liPrevOpt) EndFunc My UnAttended Event Handler , MsgBoxEx , DriveGetDriveEx and SysTray modified. Link to comment Share on other sites More sharing options...
peethebee Posted September 17, 2006 Share Posted September 17, 2006 Did not test yours, but I wrote something similar a while ago: Click4u - should be still in my fileman. peethebee vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvGerman Forums: http://www.autoit.deGerman Help File: http://autoit.de/hilfe vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 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