469,336 Members | 5,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Starting a Windows app from a windows service

Hi all,

I am trying to start a windows application that has a GUI from a Windows
service written in .NET 2.0. I have been searching on this for few days now
with no avail. When using the System.Diagnostic.Process object to start the
application (i.e Notepad), the new app runs and it is listed on the task
manger list, but the GUI doesn't show up in the desktop of the current user.
I am aware windows service (either LocalSystem, NetworkService or
LocalService) all run in a sandbox environment. I have read some where
here that there is no secure and easy way to do this, however I have no
option really and I wonder if some one could give me some hints as how would
I do this in C# or VB.NET!!.

Thanks
Mar 8 '06 #1
7 2145

"Ahmed Perlom" <pe****@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
| Hi all,
|
|
|
| I am trying to start a windows application that has a GUI from a Windows
| service written in .NET 2.0. I have been searching on this for few days
now
| with no avail. When using the System.Diagnostic.Process object to start
the
| application (i.e Notepad), the new app runs and it is listed on the task
| manger list, but the GUI doesn't show up in the desktop of the current
user.
| I am aware windows service (either LocalSystem, NetworkService or
| LocalService) all run in a sandbox environment. I have read some where
| here that there is no secure and easy way to do this, however I have no
| option really and I wonder if some one could give me some hints as how
would
| I do this in C# or VB.NET!!.
|
|
|
| Thanks
|
|

Why do you need to start the UI application from a service in the first
place, there is no easy and secure way to do this. Why don't you start the
UI application when the user logs on, set a shortcut to the application in
the startup folder in the users profile and it will start whenever the user
logs on.
Willy.
Mar 8 '06 #2
Thanks of your reply. The idea is that the windows service would monitor the
run of that application. If the application halts, or of there is an update,
the service would ask all instances of the application to stop (assuming
multiple apps are running for each user session), then ask them to -restart
again. So the service has to be in a global location monitoring whenever
users log on/off. The other tough side is that it is the current design of
the solutions by the architect and I just joined in, not much I can do ;)
Please let me know about the hard and insecure way.

Thanx


"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:eF**************@TK2MSFTNGP15.phx.gbl...

"Ahmed Perlom" <pe****@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
| Hi all,
|
|
|
| I am trying to start a windows application that has a GUI from a Windows
| service written in .NET 2.0. I have been searching on this for few days
now
| with no avail. When using the System.Diagnostic.Process object to start
the
| application (i.e Notepad), the new app runs and it is listed on the task
| manger list, but the GUI doesn't show up in the desktop of the current
user.
| I am aware windows service (either LocalSystem, NetworkService or
| LocalService) all run in a sandbox environment. I have read some where
| here that there is no secure and easy way to do this, however I have no
| option really and I wonder if some one could give me some hints as how
would
| I do this in C# or VB.NET!!.
|
|
|
| Thanks
|
|

Why do you need to start the UI application from a service in the first
place, there is no easy and secure way to do this. Why don't you start the
UI application when the user logs on, set a shortcut to the application in
the startup folder in the users profile and it will start whenever the
user
logs on.
Willy.

Mar 8 '06 #3
Make sure your service is enabled to interact with the active desktop - if
it isn't then the GUI portion may run on a desktop that is not visible to
the logged on user.
"Ahmed Perlom" <pe****@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
Hi all,

I am trying to start a windows application that has a GUI from a Windows
service written in .NET 2.0. I have been searching on this for few days
now with no avail. When using the System.Diagnostic.Process object to
start the application (i.e Notepad), the new app runs and it is listed on
the task manger list, but the GUI doesn't show up in the desktop of the
current user. I am aware windows service (either LocalSystem,
NetworkService or LocalService) all run in a sandbox environment. I have
read some where here that there is no secure and easy way to do this,
however I have no option really and I wonder if some one could give me
some hints as how would I do this in C# or VB.NET!!.

Thanks

Mar 9 '06 #4
The OP is not talking about a Service with a GUI portion, he wants to start
another GUI style application from a service.
Note also that enabling a service to interact with a desktop won't work any
longer in VISTA and beyond.
Willy.
"David Levine" <Sn*************************@wi.rr.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
| Make sure your service is enabled to interact with the active desktop - if
| it isn't then the GUI portion may run on a desktop that is not visible to
| the logged on user.
|
|
| "Ahmed Perlom" <pe****@hotmail.com> wrote in message
| news:Oc**************@TK2MSFTNGP15.phx.gbl...
| > Hi all,
| >
| >
| >
| > I am trying to start a windows application that has a GUI from a Windows
| > service written in .NET 2.0. I have been searching on this for few days
| > now with no avail. When using the System.Diagnostic.Process object to
| > start the application (i.e Notepad), the new app runs and it is listed
on
| > the task manger list, but the GUI doesn't show up in the desktop of the
| > current user. I am aware windows service (either LocalSystem,
| > NetworkService or LocalService) all run in a sandbox environment. I
have
| > read some where here that there is no secure and easy way to do this,
| > however I have no option really and I wonder if some one could give me
| > some hints as how would I do this in C# or VB.NET!!.
| >
| >
| >
| > Thanks
| >
| >
|
|
Mar 9 '06 #5
I don't get it really, you are talking about multiple applications (Windows
Apps.) you want to start, stop, restart etc. What's the interactive user's
role here? Anyway, what you are trying to achieve is exactly what MSFT is
trying to prevent by all means, and is nearly impossible to make it secure
and robust. Note also that nothing in the framework will help you with this
either, you will have to PInvoke all Win32 API's and make sure you don't
forget any.
Before you go, you should have a good understanding of:
1. Windows desktops, window stations, how they interact with each other and
how they relate to the applications and their threads using these secured
executive objects. Please consult the MSDN docs and read as much as you can
about Desktops and WinStations (search MSDN for About Window Stations and
Desktops).
2. The security context of the user running as a service (the service
account) and the context of the application launched by such a service.

When launching an application from a service you will need to:
- Create a logon session by calling Win32 LogonUser (via PInvoke) followed
by,
- a call to LoadUserProfile, this is needed to load it's environment and
profile, when done you can call...
- CreateProcessAsUser, here you need to fill the STARTUPINFO structure and
especially you need to set the 'lpdesktop' member to "Winsta0\Default", by
doing this you will start the application in the visible desktop. But there
is a catch, before you call CreateProcessAsUser you will need to add the
Logon users SID to the DACL of the Winsta0 object. Failing to do this will
prevent the launched application to use the visible desktop.
With any luck you'll have your application running, but, remember that you
have created a new logon session, that means that the application doesn't
run in the already existing interactive logon session, so each time you do
this you will create a new session and you will load the Users Registry Hive
and the environmat block into that session as HKCU, this will consume a lot
of resources when the previous session did not terminate.

Willy.


"Ahmed Perlom" <pe****@hotmail.com> wrote in message
news:ef**************@TK2MSFTNGP09.phx.gbl...
| Thanks of your reply. The idea is that the windows service would monitor
the
| run of that application. If the application halts, or of there is an
update,
| the service would ask all instances of the application to stop (assuming
| multiple apps are running for each user session), then ask them
to -restart
| again. So the service has to be in a global location monitoring whenever
| users log on/off. The other tough side is that it is the current design
of
| the solutions by the architect and I just joined in, not much I can do ;)
| Please let me know about the hard and insecure way.
|
| Thanx
|
|
|
|
| "Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
| news:eF**************@TK2MSFTNGP15.phx.gbl...
| >
| > "Ahmed Perlom" <pe****@hotmail.com> wrote in message
| > news:Oc**************@TK2MSFTNGP15.phx.gbl...
| > | Hi all,
| > |
| > |
| > |
| > | I am trying to start a windows application that has a GUI from a
Windows
| > | service written in .NET 2.0. I have been searching on this for few
days
| > now
| > | with no avail. When using the System.Diagnostic.Process object to
start
| > the
| > | application (i.e Notepad), the new app runs and it is listed on the
task
| > | manger list, but the GUI doesn't show up in the desktop of the current
| > user.
| > | I am aware windows service (either LocalSystem, NetworkService or
| > | LocalService) all run in a sandbox environment. I have read some
where
| > | here that there is no secure and easy way to do this, however I have
no
| > | option really and I wonder if some one could give me some hints as how
| > would
| > | I do this in C# or VB.NET!!.
| > |
| > |
| > |
| > | Thanks
| > |
| > |
| >
| > Why do you need to start the UI application from a service in the first
| > place, there is no easy and secure way to do this. Why don't you start
the
| > UI application when the user logs on, set a shortcut to the application
in
| > the startup folder in the users profile and it will start whenever the
| > user
| > logs on.
| >
| >
| > Willy.
| >
| >
|
|
Mar 9 '06 #6
I gotta agree with Willy on this one. Using a service like this is not a
good approach.

A cleaner alternative would be to create a monitor application, that starts
with the user - and checks the running processes. That way, it runs and
dies with that users and has all the correct rights to operate in that users
context/desktop. One feature of this is that you can add a socket
server/listener to it that accepts remote commands, allowing the app to
spawn localised applications easily at the active desktop. It will only be
a handful of code lines to create.

--
Regards

John Timney
Microsoft MVP

"Willy Denoyette [MVP]" <wi*************@telenet.be> wrote in message
news:em*************@TK2MSFTNGP10.phx.gbl...
The OP is not talking about a Service with a GUI portion, he wants to
start
another GUI style application from a service.
Note also that enabling a service to interact with a desktop won't work
any
longer in VISTA and beyond.
Willy.
"David Levine" <Sn*************************@wi.rr.com> wrote in message
news:uP**************@tk2msftngp13.phx.gbl...
| Make sure your service is enabled to interact with the active desktop -
if
| it isn't then the GUI portion may run on a desktop that is not visible
to
| the logged on user.
|
|
| "Ahmed Perlom" <pe****@hotmail.com> wrote in message
| news:Oc**************@TK2MSFTNGP15.phx.gbl...
| > Hi all,
| >
| >
| >
| > I am trying to start a windows application that has a GUI from a
Windows
| > service written in .NET 2.0. I have been searching on this for few
days
| > now with no avail. When using the System.Diagnostic.Process object to
| > start the application (i.e Notepad), the new app runs and it is listed
on
| > the task manger list, but the GUI doesn't show up in the desktop of
the
| > current user. I am aware windows service (either LocalSystem,
| > NetworkService or LocalService) all run in a sandbox environment. I
have
| > read some where here that there is no secure and easy way to do this,
| > however I have no option really and I wonder if some one could give me
| > some hints as how would I do this in C# or VB.NET!!.
| >
| >
| >
| > Thanks
| >
| >
|
|

Mar 9 '06 #7
the way I have done this in the past is to have the service modify a
registry setting / file / etc when it needs to update teh UI app.
Have your UI application periodically check the registry key - if it is set,
then have the UI app shell another (very small, generic) app that takes an
exe as a command line parameter. The UI app then ends.
The 2nd app has a timer that wait 10 secs (to allow the first app to end)
and then shells the command line parameter passed - which is the name of the
first app to be restarted.
Consideration must be given for the case when the user is currently in the
middle of doing something - if the app dies then you shall not thanked.
cheers
Terry
"Ahmed Perlom" <pe****@hotmail.com> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
Hi all,

I am trying to start a windows application that has a GUI from a Windows
service written in .NET 2.0. I have been searching on this for few days
now with no avail. When using the System.Diagnostic.Process object to
start the application (i.e Notepad), the new app runs and it is listed on
the task manger list, but the GUI doesn't show up in the desktop of the
current user. I am aware windows service (either LocalSystem,
NetworkService or LocalService) all run in a sandbox environment. I have
read some where here that there is no secure and easy way to do this,
however I have no option really and I wonder if some one could give me
some hints as how would I do this in C# or VB.NET!!.

Thanks

Apr 21 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Razzie | last post: by
reply views Thread by tshad | last post: by
3 posts views Thread by Johnny Fugazzi | last post: by
5 posts views Thread by eliasen | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.