服务无法访问映射驱动器
我在许多论坛上读到,由于没有用户登录,因此无法从服务访问映射驱动器。
问题 1)我尝试将我的服务作为登录 - 作为某个帐户,并且我将我的网络驱动器映射到该帐户中。该服务仍然无法访问它。为什么?
问题 2)从同一个服务,我调用另一个进程。该进程将在什么用户帐户下运行?
谢谢
I have read in many forums that mapped drives are not accessible from a service as no user is logged on.
Question 1) I tried making my service as a log on - as some account and i had my network drive mapped in that very account. The service still cannot access it. Why?
Question 2) From the same sevice, i invoke another process. Under what user account will the process run?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1)使用UNC路径,则不需要访问映射的驱动器号。至于为什么即使在同一帐户中运行也无法访问它们,在没有看到实际代码的情况下很难确定。
2)这取决于您如何启动该过程。如果您使用
ShellExecute()
或CreateProcess()
,那么它会在调用线程的用户帐户中运行。如果您使用CreateProcessAsUser()
、CreateProcessWithLogonW()
或CreateProcessWithTokenW()
,则它将在您传入的用户帐户中运行。1) Use UNC paths instead, then you do not need access to mapped drive letters. As to why you cannot access them even when running in the same account, it is hard to say for sure without seeing your actual code.
2) it depends on how you are launching the process. If you use
ShellExecute()
orCreateProcess()
, then it runs in the user account of the calling thread. If you useCreateProcessAsUser()
,CreateProcessWithLogonW()
, orCreateProcessWithTokenW()
, then it runs in the user account that you pass in.我在服务模式下运行 JBoss 时遇到了类似的问题,即使我执行服务,即使将“登录身份:”选项更改为已映射驱动器的同一用户,我的 Java 代码也无法访问映射驱动器。
然后我发现如果我可以使用相同的服务映射驱动器,那么它应该可以工作。
最后,在 service.bat 文件顶部添加一个简单的命令解决了该问题。
I have faced similar problem wile running JBoss in service mode, my Java code was not able to access Mapped Drive even if i execute the service even after changing "Log on as:" option to the same user who has mapped the drive.
Then I figured out that if I can map the drive using the same service, then it should work.
And finally, adding just a simple command at top of service.bat file resolved the issue.
在 XP 及更高版本上,服务无法访问映射驱动器,因为映射驱动器是每个用户的资源,因此它们取决于登录者。由于可能没有人登录,因此可能没有映射驱动器驱动器。
您的服务可能会映射驱动器本身。
Services don't have access to mapped drives on XP and beyond, since mapped drives are a per user resource, so they depend on who's logged in. Since it's possible for no-one to be logged in, it's possible that there are no mapped drives.
Your service may map a drive itself.