I am new in C#, i am having a PowerShell Script to send files to multiple PC using IP address and username, there I am using new-PSDrive. I want to create the same program in C#.
I am not sure how to do that i went through some tutorials and tried it out but stuck with Windows Impersonate Class. It was written in the post that i followed that: _If we want to share file to a shared folder we can use File.Copy(destPath, SourcePath) but its not working.
This is the Code i am trying :
WindowsIdentity idnt = new WindowsIdentity("Administrator", "Test123!");
WindowsImpersonationContext context = idnt.Impersonate();
File.Copy(@"C:\\Sent.txt", @"\\192.xxx.xxx.xxx\\SharedFolder", true);
context.Undo();
An error Pop's up : The name provided is not a properly formed account name. WindowsIdentity idnt = new WindowsIdentity("Administrator", "Test123!");
I don't know how to get proper name, i am trying this : WindowsIdentity idnt = new WindowsIdentity(Username,Password);
I also trien this ("\192.xxx.xxx.xxx\WIN-9SMSBCR4V7B\SharedFolder",Password);
The Machine on which i want to copy files is running on Vmware on same machine and i am able to send using Powershell Script.
Any suggestion would be appreciated.
Found the Solution, Here's the complete code for sending files to a remote PC using its IP address, UserName and Password for machines which are not on same DOMAIN. Here the Link which explains the use of correct LOGON PROVIDER
Hope this would help others.