Windows Service calling EnumChildWindows

Windows Service calling EnumChildWindows

am 05.11.2007 23:07:04 von systemConsultant

Can I use EnumchildWindows from a windows service to find the IE windows and
Solitaire windows belonging to the logged on user?

And if so then I'll need to know what call to use to get the users desktop
window handle to enum them - Assuming GetDesktopWindow doesn't at this point.

I can do all this in a Forms application (trying to convert to service) but
as a service it simply doesn't think there are any of those windows open.

Re: Windows Service calling EnumChildWindows

am 06.11.2007 20:37:17 von mattias.dont.want.spam

>Can I use EnumchildWindows from a windows service to find the IE windows and
>Solitaire windows belonging to the logged on user?

It depends on your OS and some other factors.

Why do you want to do this from a service?


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Re: Windows Service calling EnumChildWindows

am 06.11.2007 21:25:00 von systemConsultant

This service will need to run on few 2000 Pro, mostly XP, eventually Vista.

This is an application to log IE and Solitaire activity to make sure users
are not messing around during restricted hours. I'm trying to create a
service so it will be as elusive as possible.

I have written a working Windows version of this appication which works
perfectly.
Form1_Load() code was copied and pasted to timer1_Elapsed() in my Windows
Service version. (See below)

The call to GetBrowserWindows() passes my collection to be filled by the
callback for EnumChildWindows as it finds "IEFrame" and "Solitaire" windows.
But as service doesn't find a single window - whether I specify IEFrame or
tell it to get 'em all. I call GetDesktopWindow to use as the top level
HWND.

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string LogFilePath = @"\\d620\iespy$\IESpy.log";

CWin32API.GetBrowserWindows(LogDataCol);
StreamWriter LogFile = null;

if(File.Exists(LogFilePath))
LogFile = File.AppendText(LogFilePath);
else
LogFile = File.CreateText(LogFilePath);

for(int i=0;i {
if(LogDataCol[i].IsLogged == false)
LogFile.WriteLine(LogDataCol[i].WindowTitle + "," + LogDataCol[i].URL +
"," + LogDataCol[i].LogMachineName + "," + LogDataCol[i].LogUserName + "," +
LogDataCol[i].LogDateTime);
LogDataCol[i].IsLogged = true;
}
LogFile.Close();
}

Re: Windows Service calling EnumChildWindows

am 08.11.2007 21:46:02 von systemConsultant

I have gotten past this one. I'm not sure why it wasn't working before but
I've found that I need to reboot "A LOT" when developing a windows service.
All the building, installing, uninstalling, rebuilding, etc., just corrupts
the system and the service doesn't work as expected until a reboot. This is
on a brand new install too using .NET 2003.

Now my next problem is I need the service to "Allow interaction with
desktop". I have found most of the solution to do this. BUT, there is
something missing...
In the installer module I have coded it to enter all registry entries - and
for now I have given myself permission to the
HKLM\System\CurrentControlSet\Enum\Root node to enter the LEGACY_XXXXXXX
keys/values WHERE XXXXXXX is my service name.
I have obtained these entries by manually setting the service to "Allow
Interaction with desktop". But there is one setting not in this node or the
Service node that needs to be addressed. After install everything looks just
as I expect and looks like it should work - right? Wrong!
I still have to go the the service manager, uncheck the option, save,
re-check the option, save, and then the service works as expected. So my
question is: Is there a better way to set the "Allow Service to interact
with desktop"? Or does anyone have the faintest idea what else needs to
happen before this will work properly. It's the same problem as before -
there are no windows found - just like if the option was not set.


"Mattias Sjögren" wrote:

>
> >Can I use EnumchildWindows from a windows service to find the IE windows and
> >Solitaire windows belonging to the logged on user?
>
> It depends on your OS and some other factors.
>
> Why do you want to do this from a service?
>
>
> Mattias
>
> --
> Mattias Sjögren [C# MVP] mattias @ mvps.org
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
>