Thursday, February 14, 2008

Windows Service startup path

Ever wondered how to find the startup path for a windows service?
As in windows application,we can never find the startup path of an application using

Application.StartupPath in windows service.

We can find the startup path of a windows service using Reflection.Include the given code in your service and get the startup path returned.

private string StartPath
{
get
{
return System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly()
.GetName().CodeBase).Substring(6);
}
}

Hope this helps..

5 comments:

ashraful.asif said...

thanks

dhalsumit said...

Thanks Boss. Really helped me.

Vimal Raj said...

Thanks for letting us know that it helped you in your efforts.

ေအးၿမတ္သူဇာ said...

Great Thank! It's really helpful for me. :)

Anonymous said...

Thnx bro......

Its really good thing which i need...