473,563 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SendKeys to a differnt application from System tray App

Hi,

The problem :
Have a system tray application.Thi s has a menu item 'Exit'.
On click of this a differnt application with a UI which runs in the
background should close.
The other application requires a Keyboard combination of Ctrl + Shift + Alt
+ X to close it properly.
After closing the other application the tray app should exit. (Process.Kill
cannot be used)
The following code doesnt work all the times.
Any Ideas.
Thanks in advance
------
//
//[DllImport("user 32.dll")] public static extern int FindWindow(stri ng
lpClassName,str ing lpWindowName);

int handle = Win32.FindWindo w(null,"Basic Service");

//[DllImport("user 32.dll")]public static extern bool SetForegroundWi ndow(int
hWnd);

Win32.SetForegr oundWindow(hand le);

handle = Win32.FindWindo w(null,"Basic Service");

//[DllImport("user 32.dll")]public static extern bool SetActiveWindow (int
hWnd);

Win32.SetActive Window(handle);

SendKeys.SendWa it("+^%(x)");

processor.EndTa sks();

noiIcon.Visible = false;

this.Close();

------------------------------


Nov 17 '05 #1
1 2700
Manoj Nair wrote:
Have a system tray application.Thi s has a menu item 'Exit'.
On click of this a differnt application with a UI which runs in the
background should close.
The other application requires a Keyboard combination of Ctrl + Shift
+ Alt + X to close it properly.


Assuming that you are in control of both applications, this really just
isn't a good idea. Use some kind of interprocess communication, such as
remoting, a listening socket, or a shared file to ask the other application
to shut down; do not use SendKeys(). In particular, I've read this, although
this may not be up-to-date:

"But before you run off to use SendKeys, be advised that it's not as
reliable as SendInput. [...] For some reason, SendKeys doesn't always work.
I suspect it's a focus or timing problem-the keys are sent but then vanish
into the ether because the window you think has the focus doesn't actually
have it yet."
- http://msdn.microsoft.com/msdnmag/issues/05/01/CQA/

Also, I'm not sure why an application which runs in the background would
have a UI at all, but if it has a message loop you can probably close it by
sending it a close message. This page shows how:

http://www.codeproject.com/csharp/cskillapp.asp

I hope this helps.
--
Derrick Coetzee, MCP, MSFT (Speech Server)
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 17 '05 #2

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

Similar topics

1
7711
by: Bryan | last post by:
I am writing a C# Windows App that updates out Excel reports' modules. The app is complete, but has a problem. The only way MS allows you to unprotect the VBA code in Excel is to do it by hand or sendkeys. I hate using SendKeys, but I am forced to use them. Anyway, I have written a function that will unprotect the VBA code in the current...
5
2386
by: alfred.sehmueller | last post by:
Hello, i built a small system-tray application that listens to a hotkey builds a string and inserts the string to the active application using SendKeys.Send() The Problem is - this works only once. The hotkey is still o.k. (i also copy the string to the clipboard, here I always get the correct string that contains a timestamp) but...
2
11591
by: David Kanter | last post by:
Hi, I am relatively inexperienced with VB.Net, but I am familiar with many concepts from programming; I have some basic level of competence with C/C++ and Perl, but I just started using VB this morning. I am trying to write an .exe file that is essentially a script. It will open an application, send it some commands via the keyboard,...
11
48014
by: NVergunst | last post by:
Hello everyone. I have what I believe to be a simple question, yet I can not find anything that is helpful to me. Basically I have an application, that I want to use to control external applications. My program will run either embedded within another program or minimized to the system tray. So SendKeys is out because it only works if the...
0
7583
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
7888
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. ...
1
7642
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
6255
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...
0
5213
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
3643
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...
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.