Hi Friends,
I have developed the front end in a c# windows application.
However,
I am playing a movie in command prompt i.e. (cmd.exe). Here i am able
to view the entire data streams in command prompt i.e. how much part of
the data is played? and how much data is remaining? and other things.
Apart from this, i am able to do various operations on it like pause,
stop and seek to a particular time using the keyboard. Now, I want to
control the command prompt from my front end which is an windows
application i.e. I need to pass the commands by the button click, like i
want to pause, stop and scroll the movie which is playing in the
command prompt.
I tried using various methods of c# like sendkey,
sendmessage etc, but those are applied only to the active windows and
whenever I click the button of my front end the command prompt becomes
inactive and the front end becomes an active window, so these methods
are not applicable.
Is there any method in c# wherein I will be
able to generate the keyboard interrupt through software without
actually pressing the keyboard?
This is where I am stuck.
The
best example would be the on-screen keyboard wherein I can click on the
button on the screen and it is passing the commands to the dos.
The
exactly similar kind of application I want to use where I am having the
buttons on my front end and I want to send commands to the dos.
Kindly reply soon as possible.
Thank you,
prashant wamane
Loading
Sam HobbsPosted Dec 2, 2010, 6:15 PM
I don't know what you mean by "playing a movie". A cmd.exe window is incapable of showing graphics. Probably you are executing a console program that executes something else that creates a separate window to show the movie.
There is probably a much easier way to do what you need to do. Beginners often think that the solution is easy by sending keys to a window, but the details of doing that is often much more complicated than they realize.
As you have discovered, a command-prompt window is different from other types of windows. I get the impression however that the windows you are trying to send keys to is not a console window. Regardless, I think there is insufficient information in this thread to be able to provide useful help. I hope I am wrong and that Manikavelu's suggestion helps.
prashant wamanePosted Dec 2, 2010, 12:48 AM
Manikavelu VelayuthamPosted Dec 1, 2010, 2:17 AM
Here I am calling windows services programatically. Like this you can pass the dos command in the ProcessStart Info, and the arguments in the next line as in below code. Surely it will work.
ProcessStartInfo startInfo = new ProcessStartInfo("sc.exe");
startInfo.Arguments = string.Format(CultureInfo.InvariantCulture, "start {0} ", serviceName);
startInfo.RedirectStandardOutput = true;
startInfo.UseShellExecute = false;
using (System.Diagnostics.Process p = new System.Diagnostics.Process())
{
p.StartInfo = startInfo;
if (p.Start())
{
p.WaitForExit();
}
}