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?