views:

61

answers:

1

i have copied the exe file and it was no problem, useing the following code, but now i want to run it, can anyboyd help me on this. NOTE: i have the access to servers through remote desktop, but cant do this manually, coz there are dozens of them, cant get a program running on it like psex or whatever.

WindowsIdentity wi = new WindowsIdentity(token);

//Next I set the WindowsImportsonationContext

WindowsImpersonationContext impctx = wi.Impersonate();
System.IO.File.Copy("C:\\output.html", "\\\\PW42\\c$\\output1.html", true);
System.Diagnostics.Process p = new System.Diagnostics.Process();
try
{
    System.Diagnostics.Process.Start(@"\\PW42\c$\txt.bat");
    //runFile();
}
catch
{
    Console.WriteLine("error");
}
+2  A: 

Depending on what access you have on the server you can use a program like psexec or using WMI to launch the file remotely.

A sample psexec command would be

psexec \\computername -u remoteusername filepath(on remote computer) arguments

Psexec can copy the file beforehand if requested and can run against a list of computers instead (replacing \\computername with @computer-list.txt). With WMI you need to connect to the Win32_Process class and Create a new object to start it. The second post in this thread could work.

Unfortunately both of these options require multiple firewall rules (like RPC and WMI) to be available from the running workstation. If your company only has RDP access enabled through the firewall, neither of these will probably work.

Joshua
actually there are hundreds of servers so need to do this automatically through code, cant go there to install psexec thanks
shabby
psexec doesn't need to be installed, it takes care of that itself when run for the first time. If it can access the remote computer with admin credentials you can run psexec.
Joshua