tremolux66

SOLVED: Unable to display MsgBox from Service

3 posts in this topic

#1 ·  Posted (edited)

I'm unable to display a message box from a compiled AutoIt alerting script that is executed from a service (also a compiled AutoIt script). I used $MB_SERVICE_NOTIFICATION, but the dialog doesn't appear and the alerting script continues as if the OK button had been clicked. The service script uses ShellExecute() to launch the alerter (as opposed to a *Wait() call) so it can continue processing. Note that we used Windows Service Wrapper (winsw) to turn the compiled script into a service but haven't identified any issues from it.

I tried the one-line execute example given in this thread: Message box timeout not working

; 2097152 = $MB_SERVICE_NOTIFICATION 
$iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine  "MsgBox(2097152, ''' & $sTitle & ''', ''' & $sText & ''')"')

without the timeout code, but no luck: the MsgBox does not appear. (In any case, we don't have AutoIt installed on the target system, so it would have to be converted into a .exe file.)

We're developing and unit-testing on Win 7 Enterprise; the target OS is Win 7 Pro, and the AutoIt version is 3.3.14.2.

Any solutions or suggestions will be much appreciated. Code fragments are below.

Thanks.

 

The following code fragment is the relevant portion of the alerting script that displays the MsgBox:

[...]

; Alert the operator that there's a problem with the recording
$sFeed = $aRecInfo[6]
$sSession = $aRecInfo[2]
$sTemp = $aRecInfo[4]
$sDate = _FormatDate($sTemp)
$sTemp = $aRecInfo[5]
$sTime = _FormatTime($sTemp)
_Debug2("Inactive recording feed " & $sFeed & ", Session=" & $sSession & ", Start Date/Time=" & _
                $sDate & " " & $sTime)
                
$sErrorMsg = "ERROR: Feed " & $sFeed & " for session " & $sSession & " stopped, notify reporter immediately"

$iMbFlag = $MB_SERVICE_NOTIFICATION

_Debug1("Displaying MsgBox...")
MsgBox($iMbFlag, "INTERVIEW RECORDING ERROR", $sErrorMsg)
_Debug1("Returned from MsgBox")

[...]

 

And the calling code fragment in the service is:

; Walk through the array backwards so we don't end up evaluating an index that doesn't exist
    For $iIndex = UBound($aFeedArray)-1 To 0 Step -1

        [...]
        
            ; Before timing-out the feed, check for a .mpgpart file (=> feed may still be recording)
            $sDirPath = $sDirTemp & "\" & $sFeedTemp & "\" & $aFeedArray[$iIndex][$cSessionName]
            $sMpgPartName = GetMpgPart($sDirPath, $sFeedTemp)
            If StringLen($sMpgPartName) > 0 Then
                ; If .mpgpart file name hasn't changed in more than $iDeadFeedTime seconds, then declare feed dead
                ; ========v Test code to force error v========
                $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName]
                ; ========^ Test code to force error ^========
                _Debug2("Just set $sMpgPartName to '" & $sMpgPartName & "', should fall into dead-feed code")
                If $sMpgPartName = $aFeedArray[$iIndex][$cMpgPartName] Then
                    ; Name is same => feed is dead: alert the operator and delete the feed w/out stop-processing
                    _Debug2("Feed " & $sFeedTemp & " looks dead -- alerting the operator")
                    _Debug2("Delete GUID " & $aFeedArray[$iIndex][$cGUID])

                    ; ======== Alert app execution ========
                    ; $sAlertApp = @ScriptDir & "\" & "RecAlert.exe"
                    $iChildPid = ShellExecute($sAlertApp, $sDirPath, "", "open")
                    _Debug2("Alert app: ShellExecute(): " & _RetStr($iChildPid, @error, @extended))
                    _ArrayDelete($aFeedArray, $iIndex)                  
                Else
                    ; Otherwise, the .mpgpart name has changed, reset the timer, store the name, and continue
                    _Debug2("Feed " & $sFeedTemp & " timeout, but has new .mpgpart file -- continuing")
                    $aFeedArray[$iIndex][$cDateTime] = TimerInit()
                    $aFeedArray[$iIndex][$cMpgPartName] = $sMpgPartName
                EndIf
                ContinueLoop
            EndIf

        [...]
        
    Next

 

Edited by tremolux66
Corrected a typo that crept into the code

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi @tremolux66

Googled this question gave some pretty good results.

It seems like Windows Vista and above user interfaces generated by a service can't be seen.

There's some discussion in the links below, that may help you:

Show a message box from a Windows Service

Do you still use the MessageBox API in your Windows Service?

How to show message box in windows service

Edited by genius257
spell checking

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@genius257 Thanks for the pointers. I had assumed it was an AutoIt coding issue so I went straight to the forum, but clearly it's not. Perhaps the MsgBox() Help page could be updated to clarify this.

Since our system only has one interactive user logged-in at a time, I can probably just modify the service & rewrite the alerter script so they use a named pipe.

Thanks again.

Edited by tremolux66
Fixed a typo.

Share this post


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

  • Similar Content

    • ChipConnJohn
      By ChipConnJohn
      Hello all,
      I've scripted AutoIT to scrape a web forum I'm part of using the IE.au3 #include.  The script works great if I'm logged in, but doesn't work as a service.  Anyone have any ideas on how I might achieve that or will I have to have the computer logged in at all times?
      Thanks,
      -John
    • Kirky
      By Kirky
      Hello Again Legends of AutoIT
      I am immensely grateful for the help I was given in creating my first script which works (almost) perfectly when logged on to a PC with admin rights.
      The problem is that I need to silently install the application on to 50 PCs that do not have admin rights. We have a homemade distribution tool but basically a log on script runs, checks if your in an AD group and if you are it installs the application. The problem I have is that the user that installs the application is actually a service run as a user and this means that there is no UI.
      My script doesn't seem to run correctly or at least the application is not installed and I don't know enough about AutoIT basics (yet) to know whether it can be used in this context.
      I'm more than happy to give more information or share my script if this is not enough information to go on.
      Thanks in advance
    • musicstashall
      By musicstashall
      Excuse me, I did not understand how in the function of Main I can include hundreds of functions of my executable code ?? How to implement this?
    • Verssuss
      By Verssuss
      hi guys i want avoid to multiple MsgBox by hold Hotkey "]" in my script
       
      #include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> ;~ HotKeySet("{[}", "_boxminus") HotKeySet("{]}", "_boxplus") HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_COMPOSITED, $WS_EX_TOPMOST)) GUISetBkColor(0x00FF00) GuiCtrlCreateLabel("", 3, 3, 94, 94) GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUISetState() _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF) $box_range = 100 While 1 $pos = MouseGetPos() WinMove($hGUI, "", $pos[0] - ($box_range / 2), $pos[1] - ($box_range / 2), $box_range, $box_range) WEnd ;~ Func _boxminus() ;~ If $box_range >= 30 Then $box_range = $box_range - 10 ;~ If $box_range < 30 Then $box_range = $box_range - 1 ;~ EndFunc Func _boxplus() If $box_range < 200 Then $box_range = $box_range + 10 Else MsgBox(0,"ERROR", "Maximum size already exist") EndIf EndFunc Func On_Exit() Exit EndFunc i wish after i get first MsgBox another gonna replaced with first one or just cancel in and apeear again
      how can i make it right ???
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to make it so that when a message box pops up that the GUI will be unresponsive until that message box has been closed. From reading through the help the closest thing I can find is the WinWaitClose function, however this doesn't work fully as desired. If user tries to click on GUI the actions are more just waiting for the message box to close, so that once it closes everything happens at once. I want it so that the GUI is completely unusable until message box is closed. 
       
      Below is test code to demonstrate the problem and help explain what I want. Any advice on this?
       
      #include <GUIConstantsEx.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) local $but = GUICtrlCreateButton("Hello", 150,150,85,25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) MsgBox( 262144,"Message","Try hitting the hello button several times,without closing this window. Now close this window and see how script wasn't restricted it just was waiting and storing the instructions") WinWaitClose("Message") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK Exit case $but MsgBox(0,"","Hello") EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example