Accessing Netwok Shares

D

diephouse

I seem to be having a problem accessing networks shares. For example,
I try the following code:

File.Exists(@"\\SERVER\share");

always returns false! Or even if I map the drive

File.Exists(@"Z:\")

that will always return false as well. I can't seem to find too much
information on this. I can access the drive/share through windows
explorer so I don't understand what the problem is... any ideas?

- Dan
 
D

diephouse

Here's the clincher: the program works fine when run from the command
line. But the program is actually being launced from a printer a
printer driver. The printer driver does a _wspawn() and launches my c#
program.

I don't think printer drivers can access network shares for whateve
reason. Anyway around this????

- Dan
 
D

Dan Diephouse

This may be a permission/mapping problem most likely due to the fact
that the printer driver is spawning the application under a different
user/credentials.
You may need to use WindowsIdentity.Impersonate to impersonate a
windows user with higher authentication and/or a Windows user that has
the drive mapped

So I've been running some tests to figure out what the issue is and I'm
confounded about one portion of it. I created a C# test program which
prints the following to a textbox:

textBox1.Text += "Z Directory exists: " + Directory.Exists("z:\\") + "\r\n";
textBox1.Text += "\\\\wing\\data Directory exists: " +
Directory.Exists("\\\\wing\\data") + "\r\n";
textBox1.Text += "User: " + WindowsIdentity.GetCurrent().Name + "\r\n";
textBox1.Text += "Is Auth: " +
WindowsIdentity.GetCurrent().IsAuthenticated + "\r\n";
textBox1.Text += "Is System: " +
WindowsIdentity.GetCurrent().IsSystem + "\r\n";

I've mapped \\wing\data to z:, so I would expect the same output for
both Directory.Exists("z:\\") and Directory.Exists("\\\\wing\\data").
And it does - but as soon as I throw an impersonate() in there - even if
I'm impersonating myself, Z:\ doesn't exist but \\\\wing\\data does.

Output before impersonating myself:
Z Directory exists: True
\\wing\data Directory exists: True
User: DELL\Dan
Is Auth: True
Is System: False

Output after impersonating myself:
Z Directory exists: False
\\wing\data Directory exists: True
User: DELL\Dan
Is Auth: True
Is System: False

Why does Z:\ cease to exist!?

Bonus question: is it possible to give the NT SYSTEM account access to
z:\? Thanks,

- Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top