How to get installed exe file system path after scheduling in windows scheduler?

隐身守侯 提交于 2020-01-15 12:32:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!