I've searched around and didn't find anything useful! :(
What i want is to have my C# app doing a command to a running process. This running process is a console application and i just need to enter the command "restart".. my try was:
Process[] processes = Process.GetProcessesByName("OpenSim.32BitLaunch");
foreach (Process p in processes)
{
p.StandardInput.WriteLine("restart");
}
And i get and exectipon: StandardIn not redirected. I've tried to set RedirectStandardInput but nothing :/
Regards
Loading

VulpesRank #55 · 29.2K reputationPosted Sep 14, 2011, 11:13 AM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Sep 13, 2011, 8:02 PM EDT
Sam HobbsRank #107 · 20.5K reputationPosted Sep 14, 2011, 2:27 PM EDT
If it was important, it should be possible to inject a DLL into the process and redirect the calls to the Windows API functions but you ain't going to do that with managed code. A common way to inject code into another process is CreateRemoteThread but there are other possibilities such as Detours.
Miguel Melo3 reputationPosted Sep 15, 2011, 1:12 AM EDT
Many thanks for your help! Thanks to you i've been able to solve it :)
Mu solution was made using SetForegroundWindow and SendKeys like sugested (Note that i've already imported the DLL's that Vulpes mentioned):
System.Diagnostics.Process process = Process.GetProcessesByName("OpenSim.32BitLaunch")[0];
Process[] processes = Process.GetProcessesByName("OpenSim.32BitLaunch");
foreach (Process p in processes)
{
SetForegroundWindow(p.MainWindowHandle);
Thread.Sleep(1000);
SendKeys.SendWait("restart");
Thread.Sleep(1000);
SendKeys.SendWait("{ENTER}");
}