c# - GetDesktopWindow alternative when running as service

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?

2 Answers

  1. Elliott- Reply

    2019-11-13

    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.

  2. Elvis- Reply

    2019-11-13

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>