Execute an external application from windows service.

  • Thread starter Juan Manuel Alegría B.
  • Start date
J

Juan Manuel Alegría B.

Hi group I have been making a windows service to execute an external
application. I use a timer control, I can execute the application but
does't appear as a normal windows, just I see it in the windows task manager
as a
local service. I think it must appear as a normal process. Someone
knows about it or has any idea?

Juan Manuel Alegria B.
Jalisco, México.
 
J

John M Deal

I've never done this myself (I've done windows services just not had the
need to display a window on the desktop) so you can take this however
you'd like. However I think you may have to configure the service to
allow interaction with the desktop. To do this you need to open the
service manager, double click on your service, select the Log On tab,
and check the box that allows the service to interact with the desktop.
At least that is how you enable it on Win 2k3, but you should have
similar options in whatever version of the OS you are using. You can
probably also enable this through your setup application but like I said
I've never needed to. Hope this does it for you.

Have A Better One!

John M Deal, MCP
Necessity Software
 
A

Arnaud Debaene

John M Deal said:
I've never done this myself (I've done windows services just not had the
need to display a window on the desktop) so you can take this however
you'd like. However I think you may have to configure the service to
allow interaction with the desktop.

No!! This is a very bad idea for security reasons : the windowing
system is absolutely unsecure and should not be used in privileged
contexts such as services. Google on "shatter attack" if you are
interested in the details.
Also, it could be that interactive services would be removed in the
next Windows release for this very security concern.

To the OP : You have several options:
- if you need a window in your external app *just* for a timer, do not
use windows at all and use another timer mechanism that doesn't need a
window (System.Threading.timer for example).

- if your external window really needs and use windows (because it is
a GUI app), you should get informed on the impersonnation / DACLs /
Window Station / Desktop mechanisms of Windows. As those concepts
aren't mapped in .NET (as far as I know), you should do a bit of
unmanaged calls (Win32 Security API calls) : look at the
SetProcessWindowStation / SetThreadDesktop functions. (complete C
example at http://msdn.microsoft.com/library/d...ting_an_interactive_client_process_in_c__.asp).
Please note that you should use CreateProcessAsUser on an unprivileged
user account to avoid having an interactive process running under
SYSTEM account (always for the same shatter attack reason).

- as the 2nd option is a bit messy (especially when used in a .NET
environnement), you should perhaps reconsider your design : does your
service *really* needs to start an interactive process? Couldn't this
process be in the "Start" folder in the start menu of your user
instead? It's impossible to offer a better advice without more
knowledge about your app.

Arnaud
MVP - VC
 

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