Re: sendkeys to open the command window
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 10 Apr 2007 14:44:47 -0400
Vinki,
If you want to have an application interact with a service, you should
use remoting or WCF to make calls into your service. You can't access the
service directly to make calls.
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Vinki" <Vinki@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:B7FB5C21-E563-427F-BE4F-245AEA9CAC0E@xxxxxxxxxxxxxxxx
I will uncheck the interacting with desktop option. All I am trying to do
is
from my windows application. I am trying to call a method that exists in
the
window service. That method needs to start a process and use sendkey to
start
the process.
"Nicholas Paldino [.NET/C# MVP]" wrote:
Vinki,
Why are you trying to interact with the desktop from a service? What
exactly do you need to do? You shouldn't be interacting with the desktop
from a service, because you can have multiple desktops running on a box
at
any one time (due to terminal services) or none at all (if no one is
logged
in interactively).
--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Vinki" <Vinki@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:A839B181-4A8C-4C71-AD68-3E15110267EE@xxxxxxxxxxxxxxxx
public void sendKeysTest()
{
Process myProcess = Process.Start(@"C:\winnt\system32\cmd.exe");
SetForegroundWindow(myProcess.Handle);
if (myProcess.Responding)
SendKeys.SendWait("{ENTER}");
else
myProcess.Kill();
}
[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
I have this code in my windowservice. Option to interact with desktop
in
window service is also checked. When I click a button on the front end.
Inside the button click event, I call this method sendKeysTest, and
sendKeysTest is defined inside the window service. This program runs
fine
and
I can see cmd in my task manager that it is started, but I don't see
the
cmd
window. Is there any way I can see the cmd window. This code runs fine
when I
run this code in windows form.
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
runner.sendKeysTest();
}
catch(Exception ex)
{
string x = ex.Message;
}
}
Thanks,
Any help will be appreciated.
.
- Follow-Ups:
- Re: sendkeys to open the command window
- From: Vinki
- Re: sendkeys to open the command window
- References:
- Re: sendkeys to open the command window
- From: Nicholas Paldino [.NET/C# MVP]
- Re: sendkeys to open the command window
- From: Vinki
- Re: sendkeys to open the command window
- Prev by Date: Re: Strange problem receiving packets on a socket
- Next by Date: Re: difference between CAO and SAO in remoting
- Previous by thread: Re: sendkeys to open the command window
- Next by thread: Re: sendkeys to open the command window
- Index(es):