• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 213
  • Last Modified:

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

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
mromeo
Asked:
mromeo
  • 3
  • 2
1 Solution
 
sirbountyCommented:
What about using reflection?

System.Reflection.Assembly.GetExecutingAssembly.GetName.Name
0
 
mromeoAuthor Commented:
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
 
sirbountyCommented:
Hmm..how about:

system.diagnostics.fileversioninfo.getversioninfo(system.reflection.assembly.getentryassembly.location).FileName
0
 
mromeoAuthor Commented:
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
 
sirbountyCommented:
Glad I could assist! :^)
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now