sxyrich Posted November 24, 2014 Posted November 24, 2014 Hi When I use either $MB_SERVICE_NOTIFICATION or $MB_DEFAULT_DESKTOP_ONLY flags (or the decimal/hex equivalents) for a msgbox, the timeout doesn't work. eg #include <MsgBoxConstants.au3> MsgBox($MB_SERVICE_NOTIFICATION, "Title", "Text",10) Does not time out. I am running the latest public release (3.3.12.0) and have tried the most recent Beta (3.3.13.19) but no joy. Has anyone come across this before? any work around? Thanks Rich
Jfish Posted November 24, 2014 Posted November 24, 2014 (edited) If you change the message box flag and pass an empty string it will work. Not sure if that type can timeout. Does it have to be $MB_SERVICE_NOTIFICATION? MsgBox("", "Title", "Text",10) Edited November 24, 2014 by Jfish Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt
sxyrich Posted November 24, 2014 Author Posted November 24, 2014 Hi Jfish Thanks for your reply. Your MsgBox code does timeout, as do all the others I've tried apart from the 2 I posted. I need to run a script as SYSTEM account, which will show a message box to the logged on user (it's a PC shutdown script based on kbd/mouse inactivity and I need to display a message box to give the user the option to cancel the shutdown). The $MB_SERVICE_NOTIFICATION is perfect as it even displays on the ctrl+alt+delete screen if nobody has logged in. The problem is, I am relying on the timeout to continue the script and carry out the shutdown. Thanks Rich
johnmcloud Posted November 24, 2014 Posted November 24, 2014 (edited) If you search on the web you'll found other thread ( in other programming language ) for the same matter, MB_SERVICE_NOTIFICATION will not work with timeout. Example: How to create a timed message box The reason is: This code sample does not support the use of the MB_SERVICE_NOTIFICATION flag when calling MessageBox from a service. The message box window is not owned by the process calling MessageBox when MB_SERVICE_NOTIFICATION is specified. A simply solution: ; Johnmcloud - 2014 Local $iBegin, $iFinish, $iPID Local $sTitle = "Hello World!", $sText = "Johnmcloud!", $iTimeout = 5000 ; five seconds ; 2097152 = $MB_SERVICE_NOTIFICATION $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(2097152, ''' & $sTitle & ''', ''' & $sText & ''')"') $iBegin = TimerInit() Do Sleep(100) $iFinish = TimerDiff($iBegin) Until Not ProcessExists($iPID) Or $iFinish >= $iTimeout If $iFinish >= $iTimeout Then ; timed out so close the MsgBox WinClose($sTitle, $sText) EndIf ConsoleWrite("Continue the script" & @CR) Edited November 24, 2014 by johnmcloud
JohnOne Posted November 24, 2014 Posted November 24, 2014 This issue should probably be noted in the remarks section of the help file. Jfish 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
sxyrich Posted November 24, 2014 Author Posted November 24, 2014 Hi johnmcloud Thanks for your help on this. My original script had the flag 2097152 + 1 to give the users the option to cancel (I just removed it from my original post to not complicate things). Your solution definitely works to just continue with shutting down the PC, but I can't see a way of getting a return value from the cancel button if I use 2097152 + 1. Is there anything you can think of? I'm stuck! Thanks Rich
johnmcloud Posted November 24, 2014 Posted November 24, 2014 (edited) You can't get the return value from AutoIt3ExecuteLine. Next time write ALL THE INFORMATION or in this forum every single user criticize you for the behavior, remember it This is a simple example of inter-communication between script, autoit is single threaded so we don't have many choice. In alternative to the second file creation ( the text file ) you can use the clipboard. An advanced example can use instead >WM_COPYDATA expandcollapse popup; Johnmcloud - 2014 Local $sReturn = _MsgBox_SERVICE_NOTIFICATION_TIMEOUT("Hello World!", "Johnmcloud!", 5000) Switch $sReturn Case 1 MsgBox(64, "Result", "You have pressed OK") Case 2 MsgBox(64, "Result", "You have pressed Cancel or X") Case -1 MsgBox(64, "Result", "Timeout") Case Else MsgBox(32, "Error", "Value not expected") EndSwitch Func _MsgBox_SERVICE_NOTIFICATION_TIMEOUT($sTitle, $sText, $iTimeout) Local $iBegin, $iFinish, $iPID, $sReturn Local $sTMP_Au3 = @TempDir & "\~TEMP.au3", $sTMP_Txt = @TempDir & "\~TEMP.txt" ; create temporany au3 file - 2097152 + 1 = $MB_SERVICE_NOTIFICATION + OK Local $hFile = FileOpen($sTMP_Au3, 2) FileWrite($hFile, '#NoTrayIcon' & @CRLF) FileWrite($hFile, 'Local $hFile = FileOpen("' & $sTMP_Txt & '", 2)' & @CRLF) FileWrite($hFile, 'Local $sReturn = MsgBox(2097152 + 1, "' & $sTitle & '", "' & $sText & '")' & @CRLF) FileWrite($hFile, 'If $sReturn = 1 Then FileWrite($hFile, "1")' & @CRLF) FileWrite($hFile, 'If $sReturn = 2 Then FileWrite($hFile, "2")' & @CRLF) FileWrite($hFile, 'FileClose($hFile)') FileClose($hFile) ; end $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sTMP_Au3 & '"') $iBegin = TimerInit() Do Sleep(100) $iFinish = TimerDiff($iBegin) Until Not ProcessExists($iPID) Or $iFinish >= $iTimeout If $iFinish >= $iTimeout Then ; timed out so close the MsgBox WinClose($sTitle, $sText) ; close the MsgBox $sReturn = -1 ; TIMEOUT Else $hFile = FileOpen($sTMP_Txt, 0) If FileReadLine($hFile, 1) = "1" Then $sReturn = 1 ; OK = 1 If FileReadLine($hFile, 1) = "2" Then $sReturn = 2 ; CANCEL = 2 FileClose($hFile) EndIf FileDelete($sTMP_Au3) FileDelete($sTMP_Txt) Return $sReturn EndFunc ;==>_MsgBox_SERVICE_NOTIFICATION_TIMEOUT Edited November 24, 2014 by johnmcloud
sxyrich Posted November 25, 2014 Author Posted November 25, 2014 Thanks for your help John, and the pointers on the forum posting
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