views:

191

answers:

2

Hi All,

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

+1  A: 

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.

Remy Lebeau - TeamB
Thanks for the quick reply Remy.But the requirement states that we need to use mapped drives instead of UNC path. I have tried using UNC paths and its all working fine.About 2) - I tried the following scenario:a) Created a service and its running as some user.b) Invoked a process from within the service. (According to Remy the process should run within the same user context as provided for the service.)c) I was still unable to access the mapped drive. :( My badRequire help urgently.Thanks
Rohit
Forget about that requirement. I have seen so many of them that neglect what Microsoft forbids. UNC path is recommended. You can see even IIS does not support mapped drives, http://support.microsoft.com/kb/257174
Lex Li
There is no advantage to using a mapped drive letter over a UNC path, since a mapped drive letter maps to a UNC path anyway. The requirement needs to be loosened in this situation.
Remy Lebeau - TeamB
@Rohit, you did not answer my question regarding #2 - how exactly are you starting the new process? There are many different ways to do it. Try using CreateProcessAsUser() so that you can also use CreateEnvironmentBlock() to load the user account's environment.
Remy Lebeau - TeamB
@Remy, I believe that mapped drives have some kind of buffering that UNC path's do not. Mapped drives are often faster to access and transfer data than UNC paths. I've not confirmed this, only observed it.
Richard
A: 

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.

Richard
But you can set the service to log on as a user. right?
Rohit
Yes, but that does not mean the service has access to the user account's drive letter mappings. MSDN even says as much: http://support.microsoft.com/kb/180362
Remy Lebeau - TeamB
That is not strictly true. If you impersonate a logged on user then you will be able to access their drive mappings. I think it is more straightforward to use UNC paths, though.
Luke