Re: ProcessStartInfo.WorkingDirectory and Mapped Network Drives



Bob,

With respect, I think you've missed the point of my question and previous
comments - perhaps through a miscommunication of my own.

I'll attempt to clarify one last time...Here's the scenario:

1) I've written a Windows Service (C# and .NET Framework 2.0). This Windows
Service has its properties set such that it runs under the context of a
particular user account. For simplicity's sake, assume this user to be the
Domain Administrator account (DOMAIN\Administrator).

2) In the service's OnStart() event, the first thing I do is map a network
drive by executing the Start() method of a System.Diagnostics.Process object
whose ProcessStartInfo object has been configured such that my service
essentially executes the following command: "net use w: \\serverA\share1".
From this point forward, the mapped network drive "w:" IS available to my
service. Bob, while you are correct that by default no drives are
automatically mapped when a Windows Service starts, you are incorrect in
implying that a service cannot map a network drive or access a mapped drive
once the service is running - it can. I'll be glad to send you example code
if you would like to try it out for yourself.

3) Now that the drive "w:" is mapped and accessible to my service in a
general way (i.e., I can perform a directory listings on "w:", I can write
files to "w:", I can read files from "w:", etc.), I create a new Process
object. With this new Process object, I'd like to explicitly set its
ProcessStartInfo.WorkingDirectory property to a path on "w:" (remember, "w:"
IS available to my service at this point in time).

4) When I set the WorkingDirectory to any path on "w:", the call to Start()
fails. However, when I set the WorkingDirectory to any path on "c:", the
Start() method of the Process object executes just fine. Hence, my problem.

Hopefully, I've made it clear that I'm not having trouble with or confused
about mapping or accessing a mapped network drive from within a service. I
can prove that my service maps the drive and is accessible for things such as
directory listings, file creation, etc.

Rather, what I seek is an understanding why it seems the
ProcessStartInfo.WorkingDirectory doesn't like to be given a path that
incorporates a mapped drive when the Process object's Start() method is
called from within a service. Make more sense?

"Bob Milton" wrote:

A windows service starts before anyone logs on. At that time, there are
no mapped drives. When you log on, you can see w:, but your service has
failed by then.
Services are designed that way on purpose - all the computer has to do
is start up. SQL Server is a great example - you can set it up, put the
computer in a closet, and leave it alone and still use SQL from a client
machine.
Bob
"mhetherington" <mhetherington@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DF1EC0CE-7FCC-49FC-8920-E6FF9A1C9C55@xxxxxxxxxxxxxxxx
Thanks for the reply Bob. However, I have two comments/questions...

1) While running as a Windows Service, I can map a drive and access it
like
a local drive - it's just ProcessStartInfo.WorkingDirectory fails when I
set
it to a mapped drive. So, when you say "there are NO mapped drives" I
would
argue that there are...once you map them. Did I misunderstand your
statement?

2) In my code, ProcessStartInfo.WorkingDirectory doesn't like UNC paths
either. Have you experienced something different?

"Bob Milton" wrote:

When a windows service starts, no one is logged into the computer.
Until
someone logs in, there are NO mapped drives! So, you will have to use UNC
paths (//server/share1/dir1).
Bob

"mhetherington" <mhetherington@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message
news:D1961D07-866B-4753-99E0-01EC564E2D78@xxxxxxxxxxxxxxxx
Just discovered a critical piece of the puzzle...

The Start() method fails, as described below, only when running as a
Windows
Service. When I try the same thing from s straight Console App while
logged
in as the service account user, Start() succeed. However, when running
as
a
Windows Service it doesn't seem I can set WorkingDirectory to any
mapped
drives...even though I have confirmed that the mapped drive does exist
and
is
accessible to the service account.

So, a refinement of my question should read "Has anyone successfully
set
ProcessStartInfo.WorkingDirectory to a mapped network drive while
running
as
a Windows Service?"

"mhetherington" wrote:

Has anyone successfully called the Start() method on a
System.Diagnostics.Process object with the object's
ProcessStartInfo.WorkingDirectory set to a path on a mapped network
drive?

For example, if I have "w:" mapped to "\\serverA\share1" and set
ProcessStartInfo.WorkingDirectory = "w:\dir1", my calls to
Process.Start()
always fail with the error "The directory name is invalid".

Whereas, if I do the same thing with WorkingDirectory = "c:\dir1",
calls
to
Process.Start() always succeed.

Before anyone asks, yes the directory "dir1" does exist on w: and is
readable under the user context calling the Process.Start() method.

If no one has successfully executed Process.Start() with
WorkingDirectory
pointing to a mapped network drive, does anyone have any (MS)
reference
article confirming that this is not possible and perhaps explaining
why?

Thanks in advance.






.



Relevant Pages