How to read a file from network with different ID and Password

G

Guest

I am trying to write a program for a server application that needs to write a
file and read a file from a network driver with different network ID and
password. Here is code
using (Stream stream = new
FileStream(@"\\10.225.1.31\insight",FileMode.OpenOrCreate))
{
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine ("abc");
sw.Close();
}
The obvious trouble I am having is there is no way for me to set ID and
password.

Thanks in advance
 
N

Nicholas Paldino [.NET/C# MVP]

David,

What you want to do is call the LogonUser API function, logging in with
the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.
 
G

Guest

Do you have any source code or good web site on this ?

Thanks again

Nicholas Paldino said:
David,

What you want to do is call the LogonUser API function, logging in with
the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am trying to write a program for a server application that needs to write
a
file and read a file from a network driver with different network ID and
password. Here is code
using (Stream stream = new
FileStream(@"\\10.225.1.31\insight",FileMode.OpenOrCreate))
{
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine ("abc");
sw.Close();
}
The obvious trouble I am having is there is no way for me to set ID and
password.

Thanks in advance
 
N

Nicholas Paldino [.NET/C# MVP]

David,

The documentation I pointed you to has an example of how to do this.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Do you have any source code or good web site on this ?

Thanks again

Nicholas Paldino said:
David,

What you want to do is call the LogonUser API function, logging in
with
the user's credentials that you want to impersonate. Then, you will call
the Impersonate method on the WindowsIdentity class, passing the user
token
to be impersonated.

You can then make your call, and it will be under that other user's
account. Mind you, you need to be careful about these credentials being
embedded in your app.

Check out the documentation for the Impersonate method on the
WindowsIdentity class (the overload that takes an IntPtr parameter) for a
code example.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I am trying to write a program for a server application that needs to
write
a
file and read a file from a network driver with different network ID
and
password. Here is code
using (Stream stream = new
FileStream(@"\\10.225.1.31\insight",FileMode.OpenOrCreate))
{
StreamWriter sw = new StreamWriter(stream);
sw.WriteLine ("abc");
sw.Close();
}
The obvious trouble I am having is there is no way for me to set ID and
password.

Thanks in advance
 

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