views:

162

answers:

3

Hi, I am trying to test my WinForm app as part of the build (which runs as a service). I am using GetDesktopWindow and EnumChildWindows to find the controls I am interested in. This works perfectly when I run it in interactive session from the console, debugger, etc. but fails to find any control when run as part of the build. What can I use as an alternative to find all windows when running as a service?

+1  A: 

Typically windows services are not allowed to interact with the desktop at all (not since the introduction of windows Vista) - have you considered changing your build process to run as a scheduled task? Why are you using GetDesktopWindow anyway? It sounds like you are trying to do something odd here, if you are trying to enumerate all of the desktop windows to find your app.

1800 INFORMATION
Initially I was using the main window for my app to find child controls (which would definitely be more sensible thing to do), however it didn't find custom modal dialog boxes -- even in normal running conditions (displayed using Form.ShowDialog()).Btw. its usual practise to have the build server running as a service, Its the first time I am trying to test WinForm gui though.
Grzenio
A: 

You can fing allong the running processes ? Not wonderfull but it may works?

Toto
How would I do it? My Win api skills are pretty low.
Grzenio
Process.GetProcesses() in using System.Diagnostics and you can enumerate over alle th e processes.
Toto
But how do I get all the windows for the process?
Grzenio
Good question, no answer, sorry
Toto
A: 

Sounds like you could (if you have the appropriate access rights) use EnumDesktopWindows on the default interactive desktop.

Mattias S