Having a Problem starting an Application from a Service

  • Thread starter Thread starter Glenn
  • Start date Start date
G

Glenn

I have used this code successfully in a form application.
I tried to add the same code in a service and have not
been able to get the application to start. I have the
service starting with a local account and the Interact
with the Desktop is Checked. Windows media player seems to
start but then closes almost immediately. I would
appreciate any help.

Thanks,
Glenn



private void InitializeComponent()
{

this.p = new System.Diagnostics.Process();

this.p.EnableRaisingEvents = true;
this.p.StartInfo.FileName = "C:\\Program Files\\Windows
Media Player\\wmplayer.exe";
this.p.StartInfo.RedirectStandardError = true;
this.p.StartInfo.WindowStyle =
System.Diagnostics.ProcessWindowStyle.Maximized;
this.p.StartInfo.UseShellExecute = true;
this.p.SynchronizingObject = this;


this.p.Exited += new System.EventHandler(this.p_Exited);

// Manager
//
this.ServiceName = "Manager";
((System.ComponentModel.ISupportInitialize)
(this.timer1)).EndInit();

}// end of InitializeComponent

private void p_Exited(object sender, System.EventArgs e)
{

try
{
p.Start();
}
catch(Exception e1)
{
MessageBox.Show(e1.Message.ToString
(),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}// end of p_Exited


public void Startup()
{
p.Start();

}
 
Hi Glenn,

In your code, there are something that does not appear clear to me.

1. In service, you can not use MessageBox.Show method.
2. in your p_Exited method, you start the windows media player process
again?

You can debug your service program using the VS.net to attach into the
service's
process to see what happen after the Windows media player start.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Glenn" <[email protected]>
| Sender: "Glenn" <[email protected]>
| Subject: Having a Problem starting an Application from a Service
| Date: Fri, 26 Sep 2003 12:40:01 -0700
| Lines: 58
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOEZfnrUQuaSoGbR5ObF4RkyDRGGQ==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:187598
| NNTP-Posting-Host: TK2MSFTNGXA14 10.40.1.166
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have used this code successfully in a form application.
| I tried to add the same code in a service and have not
| been able to get the application to start. I have the
| service starting with a local account and the Interact
| with the Desktop is Checked. Windows media player seems to
| start but then closes almost immediately. I would
| appreciate any help.
|
| Thanks,
| Glenn
|
|
|
| private void InitializeComponent()
| {
|
| this.p = new System.Diagnostics.Process();
|
| this.p.EnableRaisingEvents = true;
| this.p.StartInfo.FileName = "C:\\Program Files\\Windows
| Media Player\\wmplayer.exe";
| this.p.StartInfo.RedirectStandardError = true;
| this.p.StartInfo.WindowStyle =
| System.Diagnostics.ProcessWindowStyle.Maximized;
| this.p.StartInfo.UseShellExecute = true;
| this.p.SynchronizingObject = this;
|
|
| this.p.Exited += new System.EventHandler(this.p_Exited);
|
| // Manager
| //
| this.ServiceName = "Manager";
| ((System.ComponentModel.ISupportInitialize)
| (this.timer1)).EndInit();
|
| }// end of InitializeComponent
|
| private void p_Exited(object sender, System.EventArgs e)
| {
|
| try
| {
| p.Start();
| }
| catch(Exception e1)
| {
| MessageBox.Show(e1.Message.ToString
| (),"Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
| }
| }// end of p_Exited
|
|
| public void Startup()
| {
| p.Start();
|
| }
|
 
Back
Top