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
VulpesPosted Sep 14, 2011, 3:13 PM
Miguel MeloPosted Sep 15, 2011, 5:12 AM
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}");
}
Sam HobbsPosted Sep 14, 2011, 6:27 PM
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.
Sam HobbsPosted Sep 14, 2011, 12:02 AM