473,597 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\ins ight",FileMode. OpenOrCreate))
{
StreamWriter sw = new StreamWriter(st ream);
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 1730
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.co m

"da*******@opco .com" <da************ *@discussions.m icrosoft.com> wrote in
message news:69******** *************** ***********@mic rosoft.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\ins ight",FileMode. OpenOrCreate))
{
StreamWriter sw = new StreamWriter(st ream);
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.co m

"da*******@opco .com" <da************ *@discussions.m icrosoft.com> wrote in
message news:69******** *************** ***********@mic rosoft.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\ins ight",FileMode. OpenOrCreate))
{
StreamWriter sw = new StreamWriter(st ream);
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.co m

"da*******@opco .com" <da************ *@discussions.m icrosoft.com> wrote in
message news:B3******** *************** ***********@mic rosoft.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.co m

"da*******@opco .com" <da************ *@discussions.m icrosoft.com> wrote in
message news:69******** *************** ***********@mic rosoft.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\ins ight",FileMode. OpenOrCreate))
> {
> StreamWriter sw = new StreamWriter(st ream);
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6150
by: PRM | last post by:
Hi I am sharing a network drive, by using the following code (C# Code using ASP.net /********************************************************************************** public void ShareMap(string machineName, string username, string password, string ShareName System.Management.ManagementScope sc = null ConnectionOptions co = null
3
15981
by: Divya | last post by:
Hello, I am trying to copy a file from one domain to another. I have the username and password of the destination domain. I tried a few approaches - 1. Using the Impersonator Class - http://www.codeproject.com/useritems/ZetaImpersonator.asp 2. Using WebRequest object to write the file to the destination domain - http://www.dotnet247.com/247reference/msgs/42/211482.aspx
2
3923
by: Michal Valent | last post by:
Hello, if I try to read a file on the mapped network drive, this error apears: Logon failure: unknown user name or bad password. How to set up permissions for IUSR_MACHINENAME on the mapped network drive? Thaks
11
3055
by: Andre | last post by:
Hi, I have ASP.NET application running on standalone (not part of the domain) Windows 2003. I use forms authentication for my application. The problem I have is that I need to create and read files on Windows domain network shared drives and also on shared via Samba Unix drives, which is equivalent to writing/reading to the workgroup computer. Please point, if possible, to detailed step by step description of what needs to be done. Thank...
10
4946
by: robwharram | last post by:
Hi, I'm quite frustrated in the fact that I can't even display a simple "Hello World" message on .Net. I've been through all of the groups and searched all over the place and haven't been able to figure out the solution to this problem. First off, the server is Windows Server 2003 - Web Edition (IIS 6) and I'm using .Net Framework v1.1.4322.
2
12316
by: Glen Conway | last post by:
Hi, I am trying to get the contents of a file in a hidden share on a remote server, something like '\\server.domain.com\c$\program files\application\document.xml'. When I try any of the standard streamreader, textreader or file classes I get an access denied error message (which I expect). If I go Start | Run and type this in, I get prompted for network credentials. After supplying the correct credentials I can access the file both...
3
11750
by: sck10 | last post by:
Hello, Currently, I have two web.config files on different machines (test and production). The only difference between the two is that the connectionstring and appsettings point to different data sources (testdb and productiondb). Is there a way to use something like an if statement or case statement in a web.config file to determine which connection string or app settings to use depending on the machine name? -- Thanks in advance,
9
12007
by: Mantorok | last post by:
Hi all C# v2.0 I want to update a server which is in our DMZ, to access this server I always need to enter the admin user id and password. I want to copy some files overnight to this server using a C# app, is this possible? Can I provide the credentials to enable me to access the server?
1
9625
by: ekynox | last post by:
Hi guys, have been playing with WMI to add a network printer connection to a Windows XP pc. My environment consists of a server running Windows Server 2003 and Visual Studio 2005 and a test pc running windows xp. Further, I have setup a full domain controller environment. I have managed to write the code to add the network printer and it works fine when installing the printer on the same machine the code is executing from i.e the server or...
0
7965
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
8031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5847
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5426
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3881
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3923
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1493
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.