Hello,
I'd like to re-target a running (minimized / in background) CMD.exe so that I can send input to it. I've tried different versions of code so far (which I found online), but none of it seems to be working, or it partially works. Following code is the one I find to be the best, out of the bunch I found.
Something's wrong and I obviously cannot figure out which part, so here I am, asking for help! If there's a better/different solution for this, I'd gladly take a look into it.
Thanks in advance!
I'd like to re-target a running (minimized / in background) CMD.exe so that I can send input to it. I've tried different versions of code so far (which I found online), but none of it seems to be working, or it partially works. Following code is the one I find to be the best, out of the bunch I found.
C#:
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
public void MakeWindowActive(string processName)
{
Process[] p = Process.GetProcessesByName(processName);
if (p.Count() > 0)
SetForegroundWindow(p[0].MainWindowHandle);
}
MakeWindowActive("Command Prompt");
Something's wrong and I obviously cannot figure out which part, so here I am, asking for help! If there's a better/different solution for this, I'd gladly take a look into it.
Thanks in advance!