I am running my c# application from "D:\App\program.cs" my application needs to execute a file placed in "c:\program files\software\abc.exe"
How can i set relative path in my program to execute the "abc.exe" ?
I am running my c# application from "D:\App\program.cs" my application needs to execute a file placed in "c:\program files\software\abc.exe"
How can i set relative path in my program to execute the "abc.exe" ?
It's not clear what you mean by "set relative path", but if you're using Process
and ProcessStartInfo
to run the executable, I would suggest that you use an absolute path to specify the executable, and ProcessStartInfo.WorkingDirectory
to tell the process where to run (so that relative paths will be evaluated appropriately within the new process).
EDIT: If you want the batch file to run c:\Program Files\Software\abc.exe then the contents of the batch file should be just:
"c:\Program Files\Software\abc.exe"
(Note the quotes to allow for space.)
I don't see what this has got to do with relative pathnames though.
You shouldn't be using relative path for referring something from Program Files. I would recommend to use Environment.GetFolderPath (and Environment.SpecialFolder) to get path to Program Files and then use some config setting to get reminder path to the program.
If the application is in Program Files
then you can create a batch file like
"%ProgramFiles%\software\abc.exe"