471,321 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,321 software developers and data experts.

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

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.OpenO rCreate))
{
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

Dec 2 '05 #1
3 1660
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]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:69**********************************@microsof t.com...
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.OpenO rCreate))
{
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

Dec 2 '05 #2
Do you have any source code or good web site on this ?

Thanks again

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:69**********************************@microsof t.com...
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.OpenO rCreate))
{
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


Dec 2 '05 #3
David,

The documentation I pointed you to has an example of how to do this.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:B3**********************************@microsof t.com...
Do you have any source code or good web site on this ?

Thanks again

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"da*******@opco.com" <da*************@discussions.microsoft.com> wrote in
message news:69**********************************@microsof t.com...
>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.OpenO rCreate))
> {
> 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
>


Dec 2 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by PRM | last post: by
3 posts views Thread by Divya | last post: by
2 posts views Thread by Michal Valent | last post: by
2 posts views Thread by Glen Conway | last post: by
3 posts views Thread by sck10 | last post: by
9 posts views Thread by Mantorok | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.