0

Is there a way to run local program via rdp Something like that:

Process p = new Process(); 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.RedirectStandardOutput = true;  
p.StartInfo.RedirectStandardError = true; 
p.StartInfo.RedirectStandardInput = true; 
p.StartInfo.FileName = @"G:\PSTools\PsExec.exe"; 
p.StartInfo.Arguments = @"\\tsclient calc.exe"; 
p.Start(); 
string output = p.StandardOutput.ReadToEnd(); 
string errormessage = p.StandardError.ReadToEnd(); 
p.WaitForExit();

In This case I got:

The handle is invalid. Connecting to tsclient...Couldn't access tsclient

Thanks

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
hill
  • 47
  • 3
  • please be more specific about what you want to do. Right now I am understanding it as a " I want to run a programm from a remote machine on my local machine ". Are you sure this is what you want to say? – Nico Aug 10 '17 at 08:11
  • You are trying to run something on a remote machine, then why via RDP? psexec does exactly this for you. If "tsclient" is the name of your remote computer then this will work. Also remove cmd.exe, just call calc.exe directly (or whatever program you want) else it will not work. And maybe you need the full path name to your .exe – jason.kaisersmith Aug 10 '17 at 08:12

1 Answers1

0

Finally, we have PowerShell remoting. The previous two methods that used WMI depended on remote DCOM being enabled on the computer. This may or may not be a problem but can sometimes pose a security risk. You can also use PowerShell remoting through the Invoke-Command cmdlet to kick off a process on a remote computer as well as through WSMAN, which is a newer, more secure protocol.

To do this, we'll use a combination of two cmdlets: Invoke-Command to give us the ability to run a command on the remote computer and Start-Process to actually execute the process.

Invoke-Command –ComputerName MEMBERSRV1 –ScriptBlock {Start-Process notepad.exe}

taken from here

Also this is a SO Post with the exact same question: SO

You do not need to run RDP just to start a remote process. There are multiple Librarys and Protocols for remote command execution. I would recommend to read the linked SO for more information on how to perform a psExec call.

Nico
  • 1,727
  • 1
  • 24
  • 42