restarting windows service from my application

G

ghighi

Hello,

I am working on a .Net application (aspx+webservices) that uses a
windows service I created too.
Sometimes, the exe linked to my service crashes (mostly runtime
exception), and as a consequence my application can not work. I coult
not catch or controle those exceptions, so my application needs to be
able to restart my service when it does not answer animore.
Does anyone knows how to do that?
My application is in C#. I work with VS .NET, and I have a solution
containing many projects including my application project an my windows
service project.

Any help woulf be welcome!
regards,
G.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

ghighi said:
Hello,

I am working on a .Net application (aspx+webservices) that uses a
windows service I created too.
Sometimes, the exe linked to my service crashes (mostly runtime
exception),

I suggest you to see what makes it crash in the first place.

My application is in C#. I work with VS .NET, and I have a solution
containing many projects including my application project an my windows
service project.

See the ServiceController class, you can control a service with it.
You may need extra privilegies for using it though.
 
S

Steve

Hello,

I am working on a .Net application (aspx+webservices) that uses a
windows service I created too.
Sometimes, the exe linked to my service crashes (mostly runtime
exception), and as a consequence my application can not work. I coult
not catch or controle those exceptions, so my application needs to be
able to restart my service when it does not answer animore.
Does anyone knows how to do that?
My application is in C#. I work with VS .NET, and I have a solution
containing many projects including my application project an my windows
service project.

Any help woulf be welcome!
regards,
G.


Hi G

you could use the IADsService interface which is part of Active
Directory, look here


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/iadsservice.asp


or you could use the WMI Win32_Service methods

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_service.asp

Hope this helps

cherrs

Steve

http://pretty-vacant.co.uk
 
G

ghighi

Hello,
thanks for your help.

The problem is that My exceptions are unexpected,
hardly/un-reproducible and I can not catch or control them.

I tried to use servicecontroller class; it seems good (I can get my
service status for example) but I can not start or stop my service...
what kind of privilegies do I need to use it? where do I configure it?

thx,
G.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

ghighi said:
Hello,
thanks for your help.

The problem is that My exceptions are unexpected,
hardly/un-reproducible and I can not catch or control them.

Well , you need a better logging planning, I strongly encourage you to find
the source of this exceptions
I tried to use servicecontroller class; it seems good (I can get my
service status for example) but I can not start or stop my service...
what kind of privilegies do I need to use it? where do I configure it?

IIRC only members of Administrator can do so. Dangerous proposition to give
admin priviledges to an asp.net app
 
W

Willy Denoyette [MVP]

| Hello,
|
| I am working on a .Net application (aspx+webservices) that uses a
| windows service I created too.
| Sometimes, the exe linked to my service crashes (mostly runtime
| exception), and as a consequence my application can not work. I coult
| not catch or controle those exceptions, so my application needs to be
| able to restart my service when it does not answer animore.
| Does anyone knows how to do that?
| My application is in C#. I work with VS .NET, and I have a solution
| containing many projects including my application project an my windows
| service project.
|
| Any help woulf be welcome!
| regards,
| G.
|

Your "Service" shouldn't be a Windows service in the first place, years ago
MSFT introduced COM+ just for this. It should be used whenever you needed
secure and restartable services (amongst other services like threading,
object pooling, transactions etc..). Services where invented for NT4 long
before COM+ was introduced, stay away from Windows services on anything
higher than NT4, use Component services, they are more flexible and much
easier to configure and control.

Willy.
 
G

ghighi

Thanks Willy for your advices; I'll remeber it!
Unfortunatly, the project I work on is not MY baby, I'm just its new
nany.
I work on an existing and ever running on my client's servers
application. Therefore if I can make it come along, I can't completly
change it ... :-(
So I have to make do with it!
 
W

Willy Denoyette [MVP]

| Thanks Willy for your advices; I'll remeber it!
| Unfortunatly, the project I work on is not MY baby, I'm just its new
| nany.
| I work on an existing and ever running on my client's servers
| application. Therefore if I can make it come along, I can't completly
| change it ... :-(
| So I have to make do with it!
|

Well, just keep it in mind, you may needt it when you are ready for your own
baby ;-)

Willy.
 
W

Willy Denoyette [MVP]

| Well, anyway, if I have properly understood what I have read about how
| to give admin priviledges to my app
| (see
| http://support.microsoft.com/default.aspx?scid=kb;en-us;248187&Product=asp
| , if interested) ,
| I will need admin login, password, domain etc... what I obviously won't
| know, my application being installed on several servers out of my
| control
|
| unless you know another way to process ...
|

Implement a watchdog application and run it from the scheduler service as
administaror.

Willy.
 
G

ghighi

The problem is that my service (myservice.exe) creates another process
(deamon.exe) and this is deamon.exe that has problem, not myservice.exe
If my deamon process would crash, the service would restart it, but it
actualy does not: deamon.exe opens a popup window to warn there is a
runtime exception and do not work anymore but neither do not completly
crashes ...

Nevertheless, I could try to correct my daemon app, but I don't know
how to prevent from throwing the runtime exception popup. I thougth
about putting a big try-catch in the main method but I can not find it
(seems that visual studio hides it) ...
Actually, daemon.exe is not a C# app, but a .Net C++ one and not only
I do not know this part of the application very well, but also I am
realy not expert on C++.

desperate plight!
 

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