Re: FileCopy to a shared folder

From: BLiTZWiNG (BLiTZWiNG_at_discussions.microsoft.com)
Date: 01/26/05


Date: Wed, 26 Jan 2005 14:51:04 -0800

Ok, here is the code as it stands currently.
Note that "password" has been replaced for seurity reasons.
Also note that I'm using LOGON32_LOGON_NEW_CREDENTIALS (9) now which threw a
SecurityException "Unable to impersonate user" instead of
LOGON32_LOGON_NETWORK_CLEARTEXT (8) which gave the 1326.

private void button1_Click(object sender, System.EventArgs e)
{
int token;
WindowsIdentity wid_current = WindowsIdentity.GetCurrent();

kernel.LogonUser("Administrator", "192.168.0.5", "password", 9, 0, out token);
int ret = kernel.GetLastError();
if (ret != 0) { MessageBox.Show(ret.ToString(), "Error"); return; }

// Code after this doesn't get executed yet
                        
IntPtr admin_token = new IntPtr(token);
WindowsIdentity wid_admin = new WindowsIdentity(admin_token);
WindowsImpersonationContext wic = wid_admin.Impersonate();

System.IO.File.Copy("C:\\test_read\\test.txt",
"\\\\192.168.0.5\\trent\\test.txt", true);
wic.Undo();
}

I would love to assume that I'm getting somewhere now that I'm getting a
securityexception.

Thanks for your help so far Willy.
BLiTZWiNG.

"Willy Denoyette [MVP]" wrote:

>
>
> "BLiTZWiNG" <BLiTZWiNG@discussions.microsoft.com> wrote in message
> news:4C1C3EAB-8EB3-4BB5-BA67-C60AF94522C9@microsoft.com...
> > Thanks Willy. I decided to continue pursuing this course.
> >
> > However I'm still getting error 1326 (Logon failure: unknown user name or
> > bad password) even though I can go straight to start->run and type
> > \\ip.address or domain.name\share and be granted access after entering
> > "Administrator" and the password, so I know the share is working and I
> > have
> > access to it.
> >
> > Why then would LogonUser not recognise the password? Would it have
> > something
> > to do with Active Directory? My workstation is not a part of the domain
> > I'm
> > trying to access, and for all intents and purposes, the final system wont
> > necessarily be a domain controller or part of a domain, it's just a
> > machine
> > on a network that I know the user/pass of.
> >
>
> > So here is my LogonUser("Administrator", "192.168.0.5", "password", 8, 0,
> > out token);
> >
> > I get a 1326 from that. Any ideas?
>
>
> 1326 - Means that "administrator" and/or "password" is not valid on
> 192.168.0.5. Or simply the credentials supplied are not valid.
> Could you post your code (or at least the LogonUser declaration and the
> calling code part).
>
> Willy.
> PS. LogonUser has nothing to do with AD.
>
>
>