473,573 Members | 3,030 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sendkeys to open the command window

public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.
Apr 10 '07 #1
7 8624
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******** *************** ***********@mic rosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.

Apr 10 '07 #2
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******** *************** ***********@mic rosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.


Apr 10 '07 #3
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:B7******** *************** ***********@mic rosoft.com...
>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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******* *************** ************@mi crosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.



Apr 10 '07 #4
I am using remoting. I calling that sendKeyTest method using .net remoting.

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:B7******** *************** ***********@mic rosoft.com...
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******** *************** ***********@mic rosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.


Apr 10 '07 #5
So wait, you are running the program from the service, and then trying
to make a call to send a key combination from your client, to the service,
to the process that was spawned by the service?

Why not have the client run the program directly?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:6C******** *************** ***********@mic rosoft.com...
>I am using remoting. I calling that sendKeyTest method using .net remoting.

"Nicholas Paldino [.NET/C# MVP]" wrote:
>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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:B7******* *************** ************@mi crosoft.com...
>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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******* *************** ************@mi crosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.



Apr 10 '07 #6
because client is located on some other machine and the process that i want
to start using sendkeys is on some other machine.

"Nicholas Paldino [.NET/C# MVP]" wrote:
So wait, you are running the program from the service, and then trying
to make a call to send a key combination from your client, to the service,
to the process that was spawned by the service?

Why not have the client run the program directly?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:6C******** *************** ***********@mic rosoft.com...
I am using remoting. I calling that sendKeyTest method using .net remoting.

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:B7******** *************** ***********@mic rosoft.com...
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******** *************** ***********@mic rosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.



Apr 10 '07 #7
"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:9F******** *************** ***********@mic rosoft.com...
because client is located on some other machine and the process that i want
to start using sendkeys is on some other machine.
AFAIK, you can't send keys to the cmd.exe window, don't know why you said it worked from
Winforms, did you really succeeded in sending keystrokes to the cmd window?

Why not simply start the program you want to run instead of cmd.exe? But keep in mind when
doing so, that programs started from a Service are running in the same restricted context as
the service, that is, they should not interact with the desktop, they should not assume a
user is actually logged on, they should not assume any user profile and environment to be
loaded, they should never show any dialogs or error message boxes and they should never ever
require any user response.

Anyway, the best method is let the client run the remote program via "remote desktop" or
"terminal services". Another option is "telnet" or better use the freely downloadable PS
tools from SysInternals (now owned by Microsoft)
http://www.microsoft.com/technet/sys...s/PsTools.mspx

Willy.
"Nicholas Paldino [.NET/C# MVP]" wrote:
> So wait, you are running the program from the service, and then trying
to make a call to send a key combination from your client, to the service,
to the process that was spawned by the service?

Why not have the client run the program directly?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:6C******* *************** ************@mi crosoft.com...
>I am using remoting. I calling that sendKeyTest method using .net remoting.

"Nicholas Paldino [.NET/C# MVP]" wrote:

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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:B7******* *************** ************@mi crosoft.com...
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]
- mv*@spam.guard. caspershouse.co m

"Vinki" <Vi***@discussi ons.microsoft.c omwrote in message
news:A8******* *************** ************@mi crosoft.com...
public void sendKeysTest()
{

Process myProcess = Process.Start(@ "C:\winnt\syste m32\cmd.exe");

SetForegroundWi ndow(myProcess. Handle);

if (myProcess.Resp onding)
SendKeys.SendWa it("{ENTER}");
else
myProcess.Kill( );

}
[DllImport("User 32.dll")]
public static extern bool SetForegroundWi ndow(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(o bject sender, System.EventArg s e)
{
try
{

runner.sendKeys Test();
}
catch(Exception ex)
{
string x = ex.Message;
}

}

Thanks,

Any help will be appreciated.




Apr 10 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2430
by: Tom Dacon | last post by:
"Open .Net Command Window Here" context menu for Windows Explorer: The reg file described below adds a new menu item to Windows Explorer's context menu when you right-click over a folder (or the drive root). The menu item text is "Open .Net Command Window Here". When you click it, it opens a command window positioned at that directory and...
1
1076
by: darwin.rodgers | last post by:
If I only have the .Net Framework (target computer), is there a way to open a .Net command window in order to run regasm and gacutil? The basis for my question is that I've extended the functionality of an old VB6 application by exposing methods in a .Net dll. Now I want to deploy this on computers that only have the .Net Framework. ...
2
2358
by: Jules_Anime | last post by:
Is it possible to create an onclick event which is attached to individual datalist items? I have a Datalist with some details on employees, and when you click on one we would like to open a new window which will be populated with some more data on this employee. The closest I have come is populating the...
2
3342
by: MLH | last post by:
Seems ctrl-g is the hotkey combo to open debug window. W/O using sendkeys, can I open the debug window from VBA?
0
760
by: Franky | last post by:
I can get a Command window to process a command and deposit the results in a file. What I have not been able to do is to get a command window to open so the user can input commands - and have a copy of the commands' outputs go to a file. Not sure if that is clear, what I want is the same as the first thing I mentioned except the...
5
14156
by: Vinutha | last post by:
Hi, How to open small window when i click Command Button or Command link in a webpage. Thanks, Vinutha.
3
2584
by: dsudhakara | last post by:
How to open command window open using php coding
5
1941
by: piradie | last post by:
Hello, I've been googling around, and looking into different webpages but couldn't find a clear response for the issue I need to resolve, so I was hoping any of you could give me an answer to my problem. Well, I'm trying to make a simple program that would open a cmd window and types a desired command. I've come across this: String...
1
3069
by: requeth | last post by:
I'm trying to embed a command window in a form in VB.NET. I remember back in the old days there was a button in the IDE to add the window, and I never really learned how it worked. I just downloaded Visual Basic 2008 Express Edition and the button no longer exists. Does anyone know how to initialize and embed a command window into a form or...
1
3446
by: SilverGS | last post by:
I want to automatically open a Command Window from the Startup folder in Windows XP. right now after XP starts, I click on Start run, cmd and then when the command window is open I type in a bunch of commands to start a program and I leave the command window open as the program I am running runs in the command window. How can I invoke the...
0
7701
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8029
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8204
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7794
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6424
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5293
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3735
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.