Hello!

I have an helper assembly, which runs in different applications. In
each application I would like to determine the name of the current
application.
I want to know, how I can get the name of the current service instance.
I thougt it would be possible to get the current service using
something like System.ServiceProcess... Then I can use the Name or
DisplayName property.

Has anyone an idea?

Regards,
Benjamin

Re: Get current Service and it's name by Lars

Lars
Fri Oct 21 06:33:43 CDT 2005

Hi Benjamin,

you get the current name via reflection.

Assembly.GetExecutingAssembly().GetName().Name

If your app refernce any other dll's don't
place the code there! It will return the
name of these assemblies. Place it within the
class which has the main method or any other
class which is part of the main app.

Cheers
Lars Behrmann

_________________
Nothing is impossible. UML is the key for all your problems.
AODL - Make your .net apps OpenOffice ready
http://aodl.sourceforge.net/

Benjamin Wegner schrieb:

> Hello!
>
> I have an helper assembly, which runs in different applications. In
> each application I would like to determine the name of the current
> application.
> I want to know, how I can get the name of the current service instance.
> I thougt it would be possible to get the current service using
> something like System.ServiceProcess... Then I can use the Name or
> DisplayName property.
>
> Has anyone an idea?
>
> Regards,
> Benjamin


Re: Get current Service and it's name by Benjamin

Benjamin
Fri Oct 21 08:00:16 CDT 2005

Thanks Lars,
but then I only get the name of the current assembly and this is not
the name of the service. We have different service instances using the
same assembly name with differen titles in the services list
(management console).

Therefor I need the title from the services list and not the name of
the assembly.

Regards,
Benjamin


Re: Get current Service and it's name by jch

jch
Fri Oct 21 09:16:05 CDT 2005

Your service class inherits from System.ServiceProcess.ServiceBase which has
a ServiceName property:

protected override void OnStart(string[] args)
{
if (EventLog.Exists("WindowsService1"))
EventLog.CreateEventSource("WindowsService", "Application");
EventLog.WriteEntry("WindowsService1", "Name: " + this.ServiceName,
EventLogEntryType.Information);
}

HTH, Jakob.

--
http://www.dotninjas.dk
http://www.powerbytes.dk


"Benjamin Wegner" wrote:

> Thanks Lars,
> but then I only get the name of the current assembly and this is not
> the name of the service. We have different service instances using the
> same assembly name with differen titles in the services list
> (management console).
>
> Therefor I need the title from the services list and not the name of
> the assembly.
>
> Regards,
> Benjamin
>
>

Re: Get current Service and it's name by Benjamin

Benjamin
Fri Oct 21 09:34:54 CDT 2005

thx Jakob,

as far as I understand your code snipet, this must be executed in the
servicebase class, but I want to know the service name within another
class within another assembly.

Regards,
Benjamin


Re: Get current Service and it's name by jch

jch
Mon Oct 24 01:37:02 CDT 2005

Benjamin,

> as far as I understand your code snipet, this must be executed in the
> servicebase class, but I want to know the service name within another
> class within another assembly.

Yes, my code must be run from within a class inherited from ServiceBase.
But if your code is run from within the same process as the service itself,
then it should be fairly easy for you to somehow pass the servicename to your
class? E.g. you could place the servicename in a static variable when the
service starts. This would allow any code running in the same process to get
the servicename.

Regards, Jakob.


Re: Get current Service and it's name by Benjamin

Benjamin
Thu Oct 27 02:40:18 CDT 2005

Jakob,
thats possible. I thought it would be possible to access the name of
the service (from management console) from somewhere else than a static
variable.

As far as I know the servicename property of the servicebase class is
not the name of the service in the management console.

A dirty way could be to iterate over all services within the current
system and compare the path of the service exe and the current
assembly. If it equals, this must be 'me' and I can take the name of
the service ... (I never tried this)

Regards,
Benjamin


Re: Get current Service and it's name by Tom

Tom
Sun Jan 22 22:17:02 CST 2006

Hi Benjamin

I encounter exactly the same problem as yours: Need to retrieve service name
in management console and I still not find any way to do so. I would like to
ask have you got better ways to do so now?

Many Thanks!!!

Tom

"Benjamin Wegner" wrote:

> Jakob,
> thats possible. I thought it would be possible to access the name of
> the service (from management console) from somewhere else than a static
> variable.
>
> As far as I know the servicename property of the servicebase class is
> not the name of the service in the management console.
>
> A dirty way could be to iterate over all services within the current
> system and compare the path of the service exe and the current
> assembly. If it equals, this must be 'me' and I can take the name of
> the service ... (I never tried this)
>
> Regards,
> Benjamin
>
>