SpecialFolder.MyDocuments giving correct value in a console application but not on a Windows Service

独自空忆成欢 提交于 2019-11-30 22:51:17

That is because when you run the application as a Console you are running signed in to the computer as you, the user, and can therefore access your "My Documents". When the Windows Service is running (by default) it will run as Local System which doesn't have a "My Documents" folder. This is because Windows Services run when the computer starts up and doesn't need a user signed in.

The question is, what are you trying to do with your "My Documents" folder and your Windows Service probably wants to access a location that is not user dependent?

Finally, to make it clear imagine if you had 10 users setup on the computer. Which user's "My Documents" would the Windows Service use when no-one has signed in yet?

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