问题
I have written in my console application a line System.IO.Path.GetFullPath("ApplicationSubDirectory")
to get application directory file system path.
I build this application and installed exe in my system. exe has been installed in c://ProgramFiles/AppFolder/
directory. When I execute exe then I got valid path like c://ProgramFiles/AppFolder/ApplicationSubDirectory
.
But when i scheduled this exe to run dailly basis in windows scheduler. Then I am getting wrong path. This returns me path of directory where windows scheduler is installed like c://Windows/System32/ApplicationSubDirectory
. This is wrong path.
Please help me how i get valid path after scheduling exe too.
Thanks a lot.
回答1:
This is because your console application is started by the Task Scheduler. To obtain the actual path add the following code to your application
System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
回答2:
The scheduler sets the current directory to the path mentioned above.
System.IO.Path.GetFullPath("ApplicationSubDirectory")
uses the current directory.
You could try AppDomain.CurrentDomain.BaseDirectory instead.
来源:https://stackoverflow.com/questions/16102520/how-to-get-installed-exe-file-system-path-after-scheduling-in-windows-scheduler