Accessing a remote path?

N

Neural

Hi, i searched on google for a resolution for this problem but i found
nothing interesting, i hope someone here will be able to help or at
least hint me.

The problem is simple: i'm trying to access a gile on a netwok PC,
addressing it with a UNC path (ie \\servername\share\file.txt). I use
the File object to do this, but i doesn't work because the remote PC
is on another domain, and i have to provide credentials for that
domain. I do have dose credentials, but i don't know how to use them
in c# code. Is there a way to do this? I seached in the System.IO
namespace, but found nothing...

Any help will be apreciated, thanks!
 
N

Nicholas Paldino [.NET/C# MVP]

Neural,

What you need to do is imitate that person on the other domain. To do
this, use the LogonUser API function (called through the P/Invoke layer).
Once you have a user handle, you can impersonate that user in the current
process by making a call to the Impersonate method on the WindowsIdentity
class. The documentation for the Impersonate method on the WindowsIdentity
class shows you how to do this.

Hope this helps.
 
N

Neural

What you need to do is imitate that person on the other domain. To do
this, use the LogonUser API function (called through the P/Invoke layer).

thank you Nicholas, i'll try it.
 
A

Arild Bakken

Neural said:
Hi, i searched on google for a resolution for this problem but i found
nothing interesting, i hope someone here will be able to help or at
least hint me.

The problem is simple: i'm trying to access a gile on a netwok PC,
addressing it with a UNC path (ie \\servername\share\file.txt). I use
the File object to do this, but i doesn't work because the remote PC
is on another domain, and i have to provide credentials for that
domain. I do have dose credentials, but i don't know how to use them
in c# code. Is there a way to do this? I seached in the System.IO
namespace, but found nothing...

Any help will be apreciated, thanks!


--
NEURAL
ggenga<at>hotmail<punto>com (ICQ: 8971364)

'Adepto in tutte le arti, Maestro di nessuna'

You could also use the WNetAddConnection2() API to authenticate just like
"net use" does. The drawback is that you can only authenticate as a single
user to any given server, so you need to WNetCancelConnection2() when done
with the file. This might also be a problem if mulitiple processes access
files on that server.


Arild
 

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