Shell from Timer.Elapsed in Windows Service?

  • Thread starter Rob R. Ainscough
  • Start date
R

Rob R. Ainscough

I have a Windows Service with a timer that use the .NET 2.0 Shell command.
The Shell command returns a non-zero number but Task Manager shows the
shelled exe running but there is NO visible interface (there should be
one) -- I pass AppWinStyle.NormalFocus.

If I execute the exact same in a Windows form test app, the Shell works
flawlessly.

I've tried Diagnostics.Process approach rather than Shell but have the same
results -- my app appears to run but with no visible interface??

If I run my shelled app stand alone it works fine.

Is there some kinda bizarre problem with Shell or Diagnostics.Process where
it can't be executed in timer.elapsed event due to some threading conflicts
or something? Shell is asynchronous (not wait or timeout value set) so I
don't think this would be any issue at all.

I've done the usual diagnostics and put in trace code that is logged to my
event log and following execution of both my service code and shelled app --
all indicates functioning correctly, just no visible interface (form will
not show). Like I said for Shell I've got AppWinStyle.NormalFocus and for
the Diagnostics.Process approach I set StartInfo.WindowStyle =
ProcesssWindowStyle.Normal.

I'm at a complete stand still -- Any suggestions?

Rob.
 
G

Greg Young

It's because it is running as a service. Services are not being run on your
active desktop :)

There are some hacks you can implement to allow this to happen (such as
connecting to the existing desktop or *argh* enabling desktop interaction)
but I highly recommend not doing these things. If a service needs a GUI or
to spawn a GUI, that part of the service should probably not be a service.
As an example what happens when the service wants to spawn this GUI but
there is no logged in user?

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
 
G

Guest

That is probably because the shelled application runs under the same user
account as the service, and not the user account of the logged on user.
Maybe you can try to run the service with the same user account with which
you are logged on and see if that helps?

Joris
 
B

Brendan Green

Even if the service runs as the logged in user, it won't display the app on
the desktop.

If you're wanting to launch an application that the user of the computer is
going to interact with, a Windows Service is not the way to go.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top