Sign in to follow this  
Followers 0
piuser

Running AutoIt compiled exe from windows 7 service

9 posts in this topic

Hi,

I've got a bit of an interesting problem which I'm not sure there's a solution to. Basically, one of our projects in our automated build system (Jenkins) requires the execution of a gui application.

I've crafted an AutoIt script (as an exe) to launch this gui application, fill in the appropriate fields and save a file.

All this works fine when the script is executed while I'm logged in. However when the build system is triggered, the script appears to hang. I've added ConsoleWrite() statements at various points in the script but they don't seem to be getting executed.

There are WinWaitForActive() and WinWait() calls in this script, maybe that's where the script hangs. But I can't be sure becuase of the ConsoleWrite() issue mentioned above.

I suspect that this may be a Session 0 Isolation issue, but not entirely sure if that is the issue.

Is anyone able to provide any suggestions on what the problem may be and/or how I can overcome this hurdle?

Thanks and regards

daj

Share this post


Link to post
Share on other sites



Hi thanks for the reply.

The script now logs to a file and I can see that the app hangs on execution of WinWaitActive(). I've modified the app invocation as shown in the code snippet below:

Func DebugOut($line)
   FileWrite("bmpload_runner.log", $line)
EndFunc

Func invoke_application($exec)
   DebugOut ( "Executing: " & $exec & @CRLF )
   Run($exec)
   if  WinWaitActive($g_BMPLoad_window_title, "", 1) = 0  Then
     DebugOut(@ScriptName & $time & ":" &"Timeout waiting for app window" )
   EndIf
EndFunc

When invoke_application is called, the error indicating the timeout is printed. I'm reasonably confident that Run() succeeds, but I'll add checks around it anyway.

Any ideas?

Share this post


Link to post
Share on other sites

No window will ever be active if you're not logged in, or if Windows is locked. So, it's not surprising that your WinWaitActive times out, because that window can't be active. See the Wiki FAQs for more information.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

No window will ever be active if you're not logged in, or if Windows is locked. So, it's not surprising that your WinWaitActive times out, because that window can't be active. See the Wiki FAQs for more information.

Thanks for the reply. Just had a look at the FAQ. I imagine the relevent item is http://www.autoitscript.com/wiki/FAQ#Why_doesn.27t_my_script_work_on_a_locked_workstation.3F. I'll try using WinWait then and see what appens.

Thanks again.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hmmm... part way there. Certainly replacing WinWaitActive() with WinWait() worked for the main application dialog but now I'm facing a problem in a different part of the script. One of the actions in the script is to populate a file open dialog that's displayed when one of the buttons is pressed.

The part of the script that's performing this operation is

Func open_file($file_name)
   $title = "Open"
   $edit_ctrl_id = "Edit1"
   $button_ctrl_id = "Button2"
   
   DebugOut ( "Waiting for Window " & $title )
   WinWait($title); ; TODO timeout

   commit_file_name($title, "&Open", $file_name)
EndFunc

The script now hangs at the WinWait() line. The curious thing is, the script works fine when I invoke it manually from the command line. It hangs only when invoked from a windows service.

Is there a difference in behaviour of the File Open (and Save) dialogs when invoked from a service? Is there a work-around to this issue?

Thanks

daj

Edited by piuser

Share this post


Link to post
Share on other sites

Did you setup the service to run with your credentials / windows account ? By default it uses system account.

Share this post


Link to post
Share on other sites

Did you setup the service to run with your credentials / windows account ? By default it uses system account.

I believe it's using the system account. How would it affect the script/exe?

Share this post


Link to post
Share on other sites

In many ways and it depends on many things. It would be best to setup it to run under your account. Then test to see if all works.

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
Sign in to follow this  
Followers 0