By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,419 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,419 IT Pros & Developers. It's quick & easy.

Accessing Netwok Shares

P: n/a
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

Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

di*******@gmail.com wrote:
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


Nov 16 '05 #2

P: n/a
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

Nov 16 '05 #3

P: n/a
ma**********@gmail.com wrote:
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
Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.