Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2007-04-11
5
Medium Priority
?
212 Views
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.
0
Comment
Question by:mromeo
[X]
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
5 Comments
 
LVL 67

Accepted Solution

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

System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
0
 

Author Comment

by:mromeo
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

System.Reflection.Assembly.GetExecutingAssembly.GetName.Name

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

Expert Comment

by:sirbounty
ID: 18890957
Hmm..how about:

system.diagnostics.fileversioninfo.getversioninfo(system.reflection.assembly.getentryassembly.location).FileName
0
 

Author Comment

by:mromeo
ID: 18890989
Ok,I can do this:

System.Reflection.Assembly.GetExecutingAssembly().Location

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

Expert Comment

by:sirbounty
ID: 18891045
Glad I could assist! :^)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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