When using the following class in a console application, and having at least one instance of Notepad running, GetWindowThreadProcessId
correctly returns a non-z
You could also enable the option "Allow service to interact with desktop" and see if that works. Otherwise I would have to agree with onbugz comment above.
A service runs in its own session, the infamous session 0 in Vista and Win7. That session isolates services from the user desktop, it runs in another session. Specifically to prevent a service that usually runs with a very privileged account (like LocalSystem) from interacting with the user. A security hole.
Accordingly, a service cannot see the window handles owned by another session.
Not sure why you are doing this but you typically need a helper program that presents a user interface and communicates with the service through an IPC mechanism like named pipes, sockets, .NET remoting or WCF. If you use a named pipe, prefix the pipe name with "Global\"
so all sessions can see it.
A Windows Service has no UI, so it has no window.