473,394 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Accessing another domain file system in C#

If i log into my computer as domain A and user X and password Y but then I
need to give C# application access to domain B as user F and password G. Is
this possible? or do i have to log into the computer as domain B, user F and
password G in order for the application to have permissions to domain B? I
would like to stay logged in as domain A but just give my C# application
access to domain B. In my application I need file system access that users
of domain B have but from domain A. Is this possible to do programaticaly if
I have the user name and password to a domain B account?


Nov 16 '05 #1
4 2954
Hi Daniel:

If the username and passwords on both domains match (X = F and Y = G),
you should be able to pull this off without doing anything special.

If not, you can temporarily impersonate the account on the second
domain with the WindowsIdentity class - the Impersonate method. On XP
and 2003 this is easy. On Win 2000 it is unfortunately difficult
because you need to hold a privilege reserved for the all powerful
SYSTEM account. A good rule of thumb is to avoid running under the
SYSTEM account.

Take care of the other password - don't leave it where someone can
find it. Keep it encrypted - use DPAPI if at all possible.

Hope this helps,

--
Scott
http://www.OdeToCode.com

On Fri, 13 Aug 2004 17:17:58 -0700, "Daniel"
<so*******************@yahoo.com> wrote:
If i log into my computer as domain A and user X and password Y but then I
need to give C# application access to domain B as user F and password G. Is
this possible? or do i have to log into the computer as domain B, user F and
password G in order for the application to have permissions to domain B? I
would like to stay logged in as domain A but just give my C# application
access to domain B. In my application I need file system access that users
of domain B have but from domain A. Is this possible to do programaticaly if
I have the user name and password to a domain B account?



Nov 16 '05 #2
Thanks, the Impersonate worked and I can write files while impersonating.
However, CreateDirectory doesnt seem to work. I dont think this is related
to the security because CreateDirectory doesnt seem to work even if I am
logged in to a domain that has access to a network drive. For example, if i
call CreateDirectory(\\\\devDriveA\\foo\\bar\\a\\b\\c) and
\\devDriveA\foo\bar already exists then sub directories a\b\c do not get
created. When i use CreateDirectory on my own file system, e.g.
CreateDirectory("c:\\a\\b\\c"); it works fine. Is there something that i
must do to get CreateDirectory to work on network drives?

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ug********************************@4ax.com...
Hi Daniel:

If the username and passwords on both domains match (X = F and Y = G),
you should be able to pull this off without doing anything special.

If not, you can temporarily impersonate the account on the second
domain with the WindowsIdentity class - the Impersonate method. On XP
and 2003 this is easy. On Win 2000 it is unfortunately difficult
because you need to hold a privilege reserved for the all powerful
SYSTEM account. A good rule of thumb is to avoid running under the
SYSTEM account.

Take care of the other password - don't leave it where someone can
find it. Keep it encrypted - use DPAPI if at all possible.

Hope this helps,

--
Scott
http://www.OdeToCode.com

On Fri, 13 Aug 2004 17:17:58 -0700, "Daniel"
<so*******************@yahoo.com> wrote:
If i log into my computer as domain A and user X and password Y but then Ineed to give C# application access to domain B as user F and password G. Isthis possible? or do i have to log into the computer as domain B, user F andpassword G in order for the application to have permissions to domain B? Iwould like to stay logged in as domain A but just give my C# application
access to domain B. In my application I need file system access that usersof domain B have but from domain A. Is this possible to do programaticaly ifI have the user name and password to a domain B account?


Nov 16 '05 #3
Hi Daniel:

That does seem odd, I just tested:

Directory.CreateDirectory(@"\\sql2005b2\wutemp\a\b ");

in my environment and it created both a then b in the remote wutemp
directory. (Using \\\\sql2005b2\\wutemp\\a\\b works also).

Do you see any type of exception being thrown?

--
Scott
http://www.OdeToCode.com

On Fri, 13 Aug 2004 20:07:46 -0700, "Daniel"
<so*******************@yahoo.com> wrote:
Thanks, the Impersonate worked and I can write files while impersonating.
However, CreateDirectory doesnt seem to work. I dont think this is related
to the security because CreateDirectory doesnt seem to work even if I am
logged in to a domain that has access to a network drive. For example, if i
call CreateDirectory(\\\\devDriveA\\foo\\bar\\a\\b\\c) and
\\devDriveA\foo\bar already exists then sub directories a\b\c do not get
created. When i use CreateDirectory on my own file system, e.g.
CreateDirectory("c:\\a\\b\\c"); it works fine. Is there something that i
must do to get CreateDirectory to work on network drives?


Nov 16 '05 #4
Thx Scott, u r d master.

"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ug********************************@4ax.com...
Hi Daniel:

If the username and passwords on both domains match (X = F and Y = G),
you should be able to pull this off without doing anything special.

If not, you can temporarily impersonate the account on the second
domain with the WindowsIdentity class - the Impersonate method. On XP
and 2003 this is easy. On Win 2000 it is unfortunately difficult
because you need to hold a privilege reserved for the all powerful
SYSTEM account. A good rule of thumb is to avoid running under the
SYSTEM account.

Take care of the other password - don't leave it where someone can
find it. Keep it encrypted - use DPAPI if at all possible.

Hope this helps,

--
Scott
http://www.OdeToCode.com

On Fri, 13 Aug 2004 17:17:58 -0700, "Daniel"
<so*******************@yahoo.com> wrote:
If i log into my computer as domain A and user X and password Y but then Ineed to give C# application access to domain B as user F and password G. Isthis possible? or do i have to log into the computer as domain B, user F andpassword G in order for the application to have permissions to domain B? Iwould like to stay logged in as domain A but just give my C# application
access to domain B. In my application I need file system access that usersof domain B have but from domain A. Is this possible to do programaticaly ifI have the user name and password to a domain B account?


Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Serge calderara | last post by:
Dear all, Does any one have a ready class that is able to access a configuration file and make different type of querry, read, write operation? Why re invanting the real if something already...
0
by: Ger | last post by:
Hi, I have a problem with a Windows Service that I have created accessing System.Management.dll on a W2k3 environment. The Service runs fine on an XP machine but the same Service causes an error...
1
by: Daniel | last post by:
If i log into my computer as domain A and user X and password Y but then I need to give C# application access to domain B as user F and password G. Is this possible? or do i have to log into the...
23
by: Lamberti Fabrizio | last post by:
Hi all, I've to access to a network file from an asp pages. I've red a lot of things on old posts and on Microsoft article but I can't still solve my problem. I've got two server inside the...
36
by: Thomas | last post by:
after spending countless hours trying, i give up and hope to get some help in here. on server1 i got the web myweb.com with my test.asp. in the test.asp, i'm trying to read a file from an UNC...
2
by: Jon L. Lovesky | last post by:
Hello all, I am attempting to access a remote folder from an asp.net application (all within the same domain). The application is configured for windows authentication in IIS and the asp.net...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
3
by: Gerhard | last post by:
I have an application that needs to be able to upload documents that can latter be accessed and opened by a hyperlink. I can do this easliy if I store the files in a subdirectory in the...
2
by: Gerhard | last post by:
I have a .net application that I want to run in a DMZ, with the SQL Server and file system behind another firewall. Is there a secure way to get to files from my application, or would it be better...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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...

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.