U
Ulf
Hi all,
I run into some problems when trying to copy a file to a remote
machine.
I first create with WMI a share on the remote machine (works fine),
then impersonate with admin rights and try to copy the file using the
File.Copy method. But the exception always returns a "(local)file not
found" message. Could someone give me a hint where I make a mistake in
the following code ? many thx in advance
Ulf
code :
IntPtr tokenHandle = new IntPtr(0);
tokenHandle = IntPtr.Zero;
LogonUser(UserName, HostName, Password, 2, 0, ref tokenHandle);
WindowsIdentity newId = new WindowsIdentity(tokenHandle);
WindowsImpersonationContext newUser = newId.Impersonate();
try
{
File.Copy(filePath,"\\\\" + HostName + "\\" + shareName + "\\" +
fileName,true);
}
catch(Exception copyEx)
{
MessageBox.Show("Copy failure\n" + copyEx.Message,HostName);
}
finally
{
newUser.Undo();
}
I run into some problems when trying to copy a file to a remote
machine.
I first create with WMI a share on the remote machine (works fine),
then impersonate with admin rights and try to copy the file using the
File.Copy method. But the exception always returns a "(local)file not
found" message. Could someone give me a hint where I make a mistake in
the following code ? many thx in advance
Ulf
code :
IntPtr tokenHandle = new IntPtr(0);
tokenHandle = IntPtr.Zero;
LogonUser(UserName, HostName, Password, 2, 0, ref tokenHandle);
WindowsIdentity newId = new WindowsIdentity(tokenHandle);
WindowsImpersonationContext newUser = newId.Impersonate();
try
{
File.Copy(filePath,"\\\\" + HostName + "\\" + shareName + "\\" +
fileName,true);
}
catch(Exception copyEx)
{
MessageBox.Show("Copy failure\n" + copyEx.Message,HostName);
}
finally
{
newUser.Undo();
}