Windows service and net drive

  • Thread starter Thread starter Ruben Fdez.
  • Start date Start date
R

Ruben Fdez.

Hi, I'm in troubles with Windows XP SP_2

I've mapped a net drive to Z: for the machine user Administrator.

I've build a Windows service in C# and .NET Framework 1.1. This service

must copy several files to this net drive and for that, I use de

Administrator account on the machine.

And here is the problem: File and Directory classes don't allow me to

access Z:

Somebody can help?

P.D.: If I run the app in console mode instead of a Windows service, all

works fine.

Regards and thanks.
 
Mapped drive letters are not supported in .NET as far as I know.

You have to use the UNC path.

Example:
if you have a Z drive mapped to \\server\share$\

then in your service app, you would use the path of \\server\share$\

That's how I have always done it and it works.
 
oh,

i was always under the impression that you ALWAYS need to use the UNC
path when accessing network resources
 
It depends on what you are using to perform the access. As a general
rule, I stick with UNC names over mapped drive letters (because those
mappings have a tendency to change more frequently than UNC names, IMO).

However, .NET fully supports them because the OS supports them. What
else is a drive mapping but an abstraction over a network share?
 
this is true. Thanks for clearing that up for me. Now i know, and thats
half the battle :)
 
You will need to use a network account to access a network drive, not
the administrator for the machine.

hth,
Alex
 
Connections with remoted shares are session bound, a Service doesn't share
the session with the logon user, that means you need to "map the drive" from
withing your Service, or better don't use mapped drives, use UNC paths
instead.
Mapped drives are for backward compatibility only, new developments should
never use these.

Willy.


| Hi, I'm in troubles with Windows XP SP_2
|
| I've mapped a net drive to Z: for the machine user Administrator.
|
| I've build a Windows service in C# and .NET Framework 1.1. This service
|
| must copy several files to this net drive and for that, I use de
|
| Administrator account on the machine.
|
| And here is the problem: File and Directory classes don't allow me to
|
| access Z:
|
| Somebody can help?
|
| P.D.: If I run the app in console mode instead of a Windows service, all
|
| works fine.
|
| Regards and thanks.
|
|
 
Hi,

DKode said:
oh,

i was always under the impression that you ALWAYS need to use the UNC
path when accessing network resources

No really, as Nicholas said a network drive looks like any other drive local
to your system.

The catch is that the service is not connected to the logged user session.
and the network drives are !.
So the service does not see the mapped drive as this is local to each of the
potential logged users.
 
Back
Top