473,695 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2966
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.c om> 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.c om...
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.c om> 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.Creat eDirectory(@"\\ sql2005b2\wutem p\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.c om> 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\fo o\bar already exists then sub directories a\b\c do not get
created. When i use CreateDirectory on my own file system, e.g.
CreateDirector y("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.c om...
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.c om> 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
2353
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 exist and as we share things in usegroup in general... thanks for your help
0
1935
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 once it tries to access System.Management.Dll. The service is run using a Domain Admin acoount. The code is trying to set permissions for a file and looks like this:
1
341
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 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...
23
2900
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 same NT domain, each one has its own web server. The web server is always IIS 5.0.
36
16391
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 path with a FSO: Set myFile = Server.CreateObject("Scripting.FileSystemObject").GetFile("\\server2\myshare\myfile.txt") this fails with an Permission Denied. here's the deal:
2
2894
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 worker process runs as the local ASP.NET account. When the application is about to access the remote folder I switch the security context to the remote user programmatically, then switch it back afterwards. When I run the application on my local...
0
12079
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 likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
3
1444
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 application, but we will be using multiple web servers, so the files need to be stored on a common file server. Saving them is easy enough, but how do I point a hyperlink at a file on a file server that is different from the web server? Could you please...
2
2375
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 to have a reverse proxy server in the DMZ and the webserver behind the second firewall?
0
8587
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8867
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
8841
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...
0
7688
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6511
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
4351
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
4599
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.