-
February 19th, 2017, 08:40 AM
#1
Target (CMD) window & send input
Hello there,
I'm working on a small project of mine where I'd like to start CMD and execute few commands, one after another, with time delays. This is what I got so far:
Code:
Process proc = new Process();
proc.StartInfo.FileName = Server + "\\Server.bat";
proc.StartInfo.WorkingDirectory = Server;
proc.Start();
var stopwatch = Stopwatch.StartNew();
Thread.Sleep(90000);
stopwatch.Stop();
"Server.bat" opens the CMD and the stopwatch below is used as a timer (delay) for executing next command. Problem is, I have no idea how to make the CMD window active (it currently stays active, but just in case it gets minimized ..) and send commands to it, like "dir", "cd C:\blabla" with delays in between. I've googled my *** off and not a single example / solution worked for me (most of them call CMD.exe and pass 1 command to it, right after starting). I'm still pretty new to C# and would appreciate your help!
Ow and, another side project, is there an easy way to target specific running process (selected by name?) and change its priority (example: I have Firefox running and the code changes its priority to High or Realtime)?
Thank you!
-kind regards-
Gomo
-
February 19th, 2017, 11:43 AM
#2
Re: Target (CMD) window & send input
Search the internet for "sending keystrokes to a cmd window".
As far as changing the priority of a process. You use the Process class to locate the running process and use the PriorityClass property to change its priority. However, be warned that if you change the priority of a process to something higher than the process isn't designed for, it may run continuously and starve out other processes (i.e. threads) from running. This can leave the system unusable (with the only way out is a hard reset of the machine).
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|