How get current path of exe in windows services

Hi,
 I am using windows serives. I have one windows application. Now i call the exe of this application in windows service using System.Diagnostic.Process.Start(exepath). It is working fine. But i have the problem that in windows application i get the values from ini file using current directory path that Application.startupPath(exename).

I can get the values from ini file when run windows app alone. But i put the exe to services i can't get the value. Because the current directory path shows in services that C://Windows/System32. So i put the ini file in the path. It is working fine when run the services and get the values.

But i dont want to do that every time put the file in the system32 path. I put the file in windows service path when create setup. so i want to get the values from the services directory path. How can we achieve this scenario? I believe that you catch my point that what i am telling here. Hope expecting your reply.

Thanks
LVL 23
Rajkumar GsSoftware EngineerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
s_chilkuryConnect With a Mentor Commented:
Is this what you are looking for:

System.Reflection.Assembly.GetEntryAssembly().Location
0
 
rajeshrolenConnect With a Mentor Commented:
There are various way to get it like:

Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
----------------------------------------------------
System.Reflection.Assembly.GetEntryAssembly().Location
----------------------------------------------------
string path = Assembly.GetExecutingAssembly().Location;
FileInfo fileInfo = new FileInfo(path);
string dir = fileInfo.DirectoryName;
-----------------------------------------------------
string cmdLine = Environment.CommandLine.Remove(Environment.CommandLine.Length - 2, 2).Remove(0, 1);
string workDir = Path.GetDirectoryName(cmdLine);
-----------------------------------------------------
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Hi Reajesh

 Thanks for your reply. I will try to execute the above one in my code and let you know.

Thanks
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Thanks.
I got similar solution from here as well.
http://stackoverflow.com/questions/199961/getting-full-path-for-windows-service

Raj
0
 
Rajkumar GsSoftware EngineerAuthor Commented:
Thank you
Raj
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.