starting application with a service.

G

Guest

Hi,

i have just created my first Windows service and it is working great.. my
problem is that I need to start an application in my service:
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
this.frm = new Form1();
this.frm.Show();
}

I can't find my form after starting the service!!! why????
 
N

Nicholas Paldino [.NET/C# MVP]

LZ,

In order to do this, you would have to configure your service to
interact with the desktop. However, this is a VERY BAD IDEA. You can't
always be guaranteed that there is an interactive desktop session for your
application to run in.

Rather, if you want an application with a visual component to run when
the user logs in, then you should place the application in the startup
folder, or a registry entry in the "Run" key to auto-launch the program.

Hope this helps.
 
G

Guest

Hi Nicholas,

I still don't know how to do this interact with the desktop.. do u know
where I can find more details how to make that???? I would like to try the
other thing (place the application in the startup) but I have no idea how to
do that...
--
LZ


Nicholas Paldino said:
LZ,

In order to do this, you would have to configure your service to
interact with the desktop. However, this is a VERY BAD IDEA. You can't
always be guaranteed that there is an interactive desktop session for your
application to run in.

Rather, if you want an application with a visual component to run when
the user logs in, then you should place the application in the startup
folder, or a registry entry in the "Run" key to auto-launch the program.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Lamis said:
Hi,

i have just created my first Windows service and it is working great.. my
problem is that I need to start an application in my service:
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
this.frm = new Form1();
this.frm.Show();
}

I can't find my form after starting the service!!! why????
 
B

Brian Gideon

LZ,

Go into the Service Control Manager and find your service. Open up the
property dialog box for it. On the Log On tab you'll see "Allow
service to interact with desktop". Like Nicholas said, this is not a
good idea though.

To place an application in the Startup folder open Explorer and
navigate to "\Documents And Settings\<user>\Start
Menu\Programs\Startup" and drop a shortcut in there.

Brian
 
G

Guest

Hi Brian,
this way works perfectly, thankt you... But unfortunatly I need to do the
same thing without doing it in log On tab, is it possible to do the same
thing in my code so this interaction to desktop would be check when the
service is installed????

--
LZ


Brian Gideon said:
LZ,

Go into the Service Control Manager and find your service. Open up the
property dialog box for it. On the Log On tab you'll see "Allow
service to interact with desktop". Like Nicholas said, this is not a
good idea though.

To place an application in the Startup folder open Explorer and
navigate to "\Documents And Settings\<user>\Start
Menu\Programs\Startup" and drop a shortcut in there.

Brian
 
B

Brian Gideon

LZ,

I don't know. I really recommend against doing this. If you need to
have both a service application running all the time and a GUI
application running when someone is logged in then maybe it's better to
make them two distinct applications that talk to each other via
Remoting or something. There are a lot of issues that come into play
when you allow a service to interact with the desktop directly.

Brian
 

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