How can a Windows .Net Service get its own filename (not service name)?

Posted on 2007-04-11
Medium Priority
Last Modified: 2013-12-03
I have a Windows Service written in C#.  I want to be able to get the filename of the service executable -- NOT the service name.  Does anybody know how I can do this.?  I can't use the Application class because I can't add it's reference to a Service.
Question by:mromeo
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 67

Accepted Solution

sirbounty earned 500 total points
ID: 18890830
What about using reflection?


Author Comment

ID: 18890942
That gives you back the name of your assembly, not the file name.  So if your program is called, Prog1.exe and your main assembly is MyProg1, then


returns MyProg1.   That's not the same as the file name.
LVL 67

Expert Comment

ID: 18890957
Hmm..how about:


Author Comment

ID: 18890989
Ok,I can do this:


and then get the filename off of this.  Thanks...your suggestion pointed me in the right direction!!
LVL 67

Expert Comment

ID: 18891045
Glad I could assist! :^)

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question