EXE launched from Service is invisible

  • Thread starter Thread starter CSharpner
  • Start date Start date
C

CSharpner

I've written a Windows Service (targeting .NET 2.0) which launches an
EXE with a UI. It works in that the EXE does get launched (I can see
it listed in the processes in Task Manager), but it does NOT show up.
The Windows service is running under my user account.

Here's the code that launches it:
-----------------------------------------------
var path =
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
var UI_EXE = Path.Combine(path, "ExternalDriveNotifierUI.exe");

var psi = new System.Diagnostics.ProcessStartInfo(UI_EXE,
settings.NotificationMessage);
psi.WindowStyle = ProcessWindowStyle.Normal;
var process = new Process();
process.StartInfo = psi;
process.Start();

TIA
 
I've written a Windows Service (targeting .NET 2.0) which launches an
EXE with a UI. It works in that the EXE does get launched (I can see
it listed in the processes in Task Manager), but it does NOT show up.
The Windows service is running under my user account.
This is by design. Services cannot interact with the desktop unless you
configure that they can. This is not normally done because services
typically run under elevated privileges, and allowing arbitrary processes to
interact with them through an interactive window would be a bad idea. In
Vista, it stopped working altogether because even if you set the service to
interactive, it will run in a separate desktop station especially for
services, so the user(s) still can't see the interactive stuff (but other
services could interact with the window).

The usual way to do what you want is to launch the interactive component as
an autostart program (through the appropriate registry or Start Menu
settings) and have the service and it communicate through IPC. If your
service is doing nothing that must be done even if no users are logged on,
you can eliminate it altogether and stick with the user component. On the
other hand, if your service is doing things that are so critical that
someone must be informed if something goes wrong, you should account for the
scenario where no user is logged on.
 
On 2010-08-19 18:25, CSharpner wrote:> I've written a Windows Service (targeting .NET 2.0) which launches an

This is by design. Services cannot interact with the desktop unless you
configure that they can. This is not normally done because services
typically run under elevated privileges, and allowing arbitrary processesto
interact with them through an interactive window would be a bad idea. In
Vista, it stopped working altogether because even if you set the service to
interactive, it will run in a separate desktop station especially for
services, so the user(s) still can't see the interactive stuff (but other
services could interact with the window).

The usual way to do what you want is to launch the interactive component as
an autostart program (through the appropriate registry or Start Menu
settings) and have the service and it communicate through IPC. If your
service is doing nothing that must be done even if no users are logged on,
you can eliminate it altogether and stick with the user component. On the
other hand, if your service is doing things that are so critical that
someone must be informed if something goes wrong, you should account for the
scenario where no user is logged on.

Yep, I was aware of most of that, but thought that launching a GUI in
a separate process would work around it. Obviously, it doesn't.
Alrighty, I'll be re-architecting it. I believe I can get away
without the service then, assuming I can consume USB insert and
removal notifications in a normal EXE.

Thanks.
 
I believe I can get away without the service then, assuming I can consume
USB insert and removal notifications in a normal EXE.
WM_DEVICECHANGE is what you're looking for.
 
Back
Top