Rohit
Rohit

Reputation: 11

Service not able to access a mapped drive

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

Upvotes: 1

Views: 7607

Answers (3)

deenaik
deenaik

Reputation: 753

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.

net use x: \\SERVERNAME\SHARENAME

Upvotes: 1

Richard
Richard

Reputation: 192

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.

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 597971

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() or CreateProcess(), then it runs in the user account of the calling thread. If you use CreateProcessAsUser(), CreateProcessWithLogonW(), or CreateProcessWithTokenW(), then it runs in the user account that you pass in.

Upvotes: 4

Related Questions