Hello All,

I am copying file from one machine to another machine
after that execute that file on remote computer using c#.

I am using below command to copy file
File.Copy(sourcePath, DestinationPath, true);

and

ManagementClass remote_Class = new ManagementClass ("\\machineName\root\\cimv2:Win32_Process");
object[] remoterun = { destPathwithFileName, null, null, 0 };
remote_Class.InvokeMethod("Create", remoterun);

to execute that executable on remote machine.

Now I code in which I can provide domain\username and password.
I want that process to be executed by domain user on remote machine
Or process to be executed by username and password which I've provided in code.
I don't want to use LogOnUser()

In future just boost your orignal thread instead making a duplicate with a crap name.

This will get the windows identity of the machine it is executed on but make sure you add the using System.Security.Principal library.

public void getName()
        {
             // Retrieves and stores WindosIdentity in textBox1
             textBox1.Text = WindowsIdentity.GetCurrent().Name.ToString();
        }

As for the password i coulden't find out how to do it when i did a project which required it so let me know if and how you manage it.

########################################################################################
Thanks..for suggestion... but I didn't know how to boost up the original thread so I've created the new thread.Also I tried to delete the new thread but I didn't find the delete button.
########################################################################################

Here I don't want the windows Identity of machine on which the process is executed.
I want that process or any other things such as copying,deleting or any other task should get execute with the user name which I've provided explicitly.

For ex:

Domain : <Domain Name>
User Name : <Provide Username>
Password : <Provide Password>
Machine Name : <Machine on which user wants to execute Task>

<Execute Button>

When user clicks on execute button any task such as copy,delete or execute gets execute on user provided machine with above mentioned username and password

Thanks
##K.K##

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.