I have a systemtray application (C#, Windows Forms). Next to this executable I will have another x amount of executables (written in C#) that must somehow send a message (preferably in string format) to the system tray application.
I do NOT want to install an entire Windows service for this.
It is NOT client-server. It all happens on the same PC. Using a listener combined with sockets would be to troublesome and it might even be blocked by it's own firewall I think.
I'm looking for something similar to a console application that can handle parameters on it's main function. Only this time for an already running Windows Form application.
Is it possible to somehow make a global function/procedure in the system tray application that can be called by other executables? Like "global void PerformAction(params here){..}"? This would seem to be the best solution but I'm not sure if .NET 4 supports this.
Example: executable X1.exe sends message "perform action [A] param [B]" to the system tray application and then terminates itself. The system tray application will then read that string and then knows that it needs to call function A with parameter "B".
But how do I send/receive the message?
Thank you.
Without resorting to WCF - you can use a simple wrapper over Named Pipes - like this one I posted as an answer to another question.
Hope this helps!
For local communication you could try anonymous pipes.
Link: http://msdn.microsoft.com/en-us/library/bb546102.aspx
You can also check out the remote method invocation.
Here is an example:
http://www.codeproject.com/Articles/14791/NET-Remoting-with-an-easy-example
There is a very handy method available to native application, i.e. window messages. With some hack, you can also use it with your .net application.
I would suggest you to refer to
SendMessage and SendMessageA api functions. You might have to write some unsafe code though.
If you used self hosted Asp.Net Web API, then you could use simple http calls to that application to execute methods. This is nice because you can test it using fiddler or anything that can send an http request.
Here is a link for an example.
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api
The easiest solution to me seemed to use a WCF service (inside the tray application) as Steve B mentioned.
I used this tutorial: http://www.switchonthecode.com/tutorials/wcf-tutorial-basic-interprocess-communication.
I haven't heard of piping before but I think that the above link uses a WCF Service with piping. It did solve my problem.
Thanks for the many solutions provided (and so fast).
Related
I'm new in programming with .Net and C# and, as said in the title, I have a WPF app which is accessible in a system tray icon and I want to run it a windows service.
Typically, I want an output like it was described in an answer provided in a discussion here.
If you want it in the system tray I think what you'll have to do is make it a Windows service. I've only written 1 Windows Service and that was years ago, but I believe that's what you'll have to do. If I'm correct about writing a Windows service, then what I would suggest you do is create a new Visual Studio solution and add two projects to it. One would be a DLL which would run as a Windows service. The second project would be a WPF project that will be your UI the user interacts with. Then you'll have to use some messaging system to communicate between the two. For the action messages that would mimic what Outlook does, I've used some WPF toast messages to accomplish that. If you Bing/Google "WPF toast popup" you'll get lots of results.
I have many searched in Internet and find some helpful answers like:
URL1
You can't, not directly, because the windows service will necessarily start when the machine does, not when a user logs in. The service will also be running in a different context, likely as a different user. What you can do is to write a separate system tray based "controller" that interacts with the service.
URL2
It needs some effort to achieve. Well, just two hints: 1) use static property System.Environment.UserInteractive to detect in which mode your application is running, see http://msdn.microsoft.com/en-us/library/system.environment.userinteractive.aspx; 2) get rid of app.xaml, because it will force starting WPF Application in all cases; instead, create and run and instance of System.Windows.Application (or better, a specially derived class) explicitly and only for interactive mode, see http://msdn.microsoft.com/en-us/library/system.windows.application.aspx.
And, I could not apply their instructions.
Thanks advance!
I have a Windows WPF application running in the background at all times. I have registered a URL protocol in with the application called WTL:. The protocol works when the application is closed, but how do I respond to it when the application is open or running in the background? I have clients that are using WinXP, so the new protocol handling in Win8 isn't sufficient.
I figured OnNavigated or OnActivated might work, but the protocol doesn't work with those. Should I run something that is always listening to the protocol? Help.
Thanks!
OK - i had to read over this two times but now i think i know what you mean. I have had a similar task, not with WPF but in WinForms... (almost the same in that case).
I don't know what "WTL" does exactly, because i registered my own protocol manually at the application startup.
You can view the current settings by opening the registry editor and goto HKEY_CLASSES_ROOT
Beneath you can find your "protocol" (dont know yours, so for example i take "callto://")
Browse to the command-subkey HKEY_CLASSES_ROOT\callto\shell\open\command - The default entry points to your application. The value must look like:
"path_to_your_application.exe" "%1" (including the double-quotes!)
Important is the "%1"
This value represents the argument for your application instance.
Reading commandline args isn't really a complicated task in .net.
But it's getting a little bit tricky, if you allow only one instance!
For me the best approach for a single-instance application & getting those
"second instance-commandline-args" can be found under:
Codeproject: WPF Single Instance Application
Long story short: A request to your application can look like:
"callto://008291478624599"
In which the number will be filled in the args for your 2nd application startup request (the %1)
I have a WPF application, and i need to launch some actions (and receive return values) starting from another console application.
I encountered many problems so i don t know exactly how to proceed:
1- I tried to use command lines with arguments(it worked to launch the wpf application), but i couldn't receive return Values, because they are only returned on application shutdown. Also it doesn't fit my need since some actions must be called while the wpf app is still running.
2- I thought abt developping a small dll to communicate between Console and WPF application, but i don't know what technology would be light, efficient and fit my needs.
Has any one achieved similar task in the past? If so, how did you go about it?
Thanks,
What you are looking for is usually termed 'Inter-process communication'. Named pipes are a type of IPC and can be used in .net. This guide should get you started.
You could use WCF technology to achieve this. Define contract in you wpf application, where you should set your action logic - methods, by which you want to manage your application. If it is single sided, use netTcpBinding and create endpoint in your WPF application - it is a listener from the commands from outeside. Then in your your console application add proxy class of your wpf application, using svcutil. This will allow you to send your commands. If you do everything right - this should work. I suppose you have 1 wpf application and 1 console application.
You may launch your wpf app and then use:
Named Pipes - the simplest way but you must create a protocol of interaction between apps. You may transfer serialized objects for example. (example);
Shared files;
WCF - most powerfull and complex technology.
I dont know whether this is possible but it would be great if there is a solution for this:
I have an asp.net webpage. When the user opens a webpage. I would like that webpage to trigger to run a .net application running on the client machine. In addition, during that trigger, that webpage also passes some parameters as arguments to the .net application.
I hope to get some ideas how to achieve this issue somehow?
thanks in advance.
Pretty vague question, but you might look into either:
SignalR - a long polling library for ASP.Net that lets you make calls to client side code from the server side "faking a persistently open connection"
Node.js - a javascript library for the server-side.
I would suggest starting with SignalR
Edit:
https://github.com/SignalR/SignalR
http://chatapp.apphb.com/
See this question: Running application from browser ASP.NET
In short you can't do this with HTML & JS, you may be able to with silverlight depending on what you want to do
Do you have control over the client-side app? If so, Click Once is one approach. Silverlight is another.
For a general purpose solution, the app either needs to be registered with the browser for a specific MIME type (this is how the browser knows to start Acrobat Reader for PDF files, for example), or you would need to create and have your users install an Active-X plug-in (native C++ code, though).
I need to automate FileMon.exe to startup with filters, save out the log it generates, and then exit.
My solution has been to write an assist application that will do all of this. Which has worked on starting up with specified filters and killing the process, but I still need it to save the log. Do you think it would be silly to send the application keystrokes to save the log? For instance I would send an Alt+F, Alt+S, type filepath, Enter.
How can you send keystrokes like above to another process that is running in C#?
As I know, you have to invoke some of native APIs:
-FindWindow to find parent windows you want to work with
-FindWindowEx to find true windows you'll send message to
-SendMessage to send key strokes to those windows
Details of these APIs, refer at MSDN :)
You can use Windows.Forms.SendKeys to send keystrokes to the active application.
Thanks for all the answers and help guys... I'm actually going to write and invoke a perl script using Win32::GuiTest.
That's probably a deaad end. You should look and see if the application (or one of its dependent DLLs) exposes the proper API calls to do what you are trying to do. If you had to do it by keystrokes, you could look into some kind of macro program like MacorMaker.
You could use powershell and the windows automation cmdlets up on www.codeplex.com/wasp to do this.
-Oisin
Use something like AHK (Auto HotKey) it is a simple language that can be compiled to an EXE and is designed for automating the keyboard and mouse.
Also the IRC Channel and Forums always have people willing to help if need be.