Could not find a part of path error on server

爷,独闯天下 提交于 2019-12-02 05:36:31

You probably assumed that when you installed your service, it'd run on the path where it is installed from but services on Windows are run by "Service Control Manager" (scm) which is usually located on C:\Windows\System32

So, your service gets the C:\Windows\System32 value as CurrentPath()

You could try:

startupPath = System.AppDomain.CurrentDomain.BaseDirectory;

*Edit: For those who might want to check the path for scm, the file that you need to check is sc.exe As in sc command that you use to install,start,etc. a service.

It looks like access right issue. Unless granted you need administrative privileges to access C:\Windows\System32 folder. On your local machine you might have access to path but on server you do not. Insted of setting C:\Windows\System32 as startupPath in your code, try with Path.GetTempPath.

https://msdn.microsoft.com/en-us/library/system.io.path.gettemppath(v=vs.110).asp

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