A small code example would be appreciated. I have tried using this....(which
I found on this forum)
[DllImport("adva pi32.dll")]
public static extern int LogonUser(Strin g lpszUsername, String
lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider , out
IntPtr phToken);
[DllImport("adva pi32.DLL")]
public static extern bool ImpersonateLogg edOnUser(IntPtr hToken); //
handle to token for logged-on user
[DllImport("adva pi32.DLL")] public static extern bool RevertToSelf();
public static void Main(string[] args)
{
IntPtr admin_token;
string password = ConfigurationSe ttings.AppSetti ngs["NetDriveAccoun tPwd"];
WindowsIdentity wid_current = WindowsIdentity .GetCurrent();
//WindowsIdentity wid_admin = null;
//WindowsImperson ationContext wic = null;
try
{
Console.WriteLi ne("Copying file...");
if (LogonUser("use rName", "192..168.1 .1", password, 9, 0, out
admin_token) != 0)
{
ImpersonateLogg edOnUser(admin_ token);
Console.WriteLi ne(WindowsIdent ity.GetCurrent( ).Name);
//Console.WriteLi ne(admin_token. ToString());
//wid_admin = new WindowsIdentity (admin_token);
//wic = wid_admin.Imper sonate();
System.IO.File. Copy("C:\\email Output.txt",
"\\\\192.168.1. 1\\FolderName", true);
Console.WriteLi ne("Copy succeeded");
}
else Console.WriteLi ne("Copy Failed");
}
catch (System.Excepti on se)
{
int ret = Marshal.GetLast Win32Error();
Console.WriteLi ne(ret.ToString (), "Error code: " + ret.ToString()) ;
Console.WriteLi ne(se.Message);
}
finally
{
RevertToSelf();
//if (wic != null) wic.Undo();
}
//Console.ReadLin e();
}
--
But I kept on getting error "Access to the path \\\\192.168.1.1 \\FolderName
is denied"
Any help would be appreciated.
Ruepen
"Ruepen" wrote:
I need to write to a file on a shared drive on another server using user
credentials.
I can't have this permanently mapped either due to application server
restrictions that my app is running on.
Can this be done using C# classes only?
--
Ruepen