472,090 Members | 1,336 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,090 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 2849
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Serge calderara | last post: by
23 posts views Thread by Lamberti Fabrizio | last post: by
2 posts views Thread by Jon L. Lovesky | last post: by
3 posts views Thread by Gerhard | last post: by
2 posts views Thread by Gerhard | last post: by
reply views Thread by leo001 | 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.