Solved

How get current path of exe in windows services

Posted on 2010-11-10
5
698 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Rajkumar Gs
[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
5 Comments
 
LVL 9

Accepted Solution

by:
s_chilkury earned 250 total points
ID: 34109374
Is this what you are looking for:

System.Reflection.Assembly.GetEntryAssembly().Location
0
 

Assisted Solution

by:rajeshrolen
rajeshrolen earned 250 total points
ID: 34109390
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
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 34109397
Hi Reajesh

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

Thanks
0
 
LVL 23

Author Comment

by:Rajkumar Gs
ID: 34487719
Thanks.
I got similar solution from here as well.
http://stackoverflow.com/questions/199961/getting-full-path-for-windows-service

Raj
0
 
LVL 23

Author Closing Comment

by:Rajkumar Gs
ID: 34487724
Thank you
Raj
0

Featured Post

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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