Can a Windows Service receive Windows Messages? - windows

I created an application to receive a broadcasted windows message which works fine. When I turn it into a service, install it, and start the service, the service doesn't receive the message.

The service probably must be granted access to the desktop. Do this from the Service properties, "Log On" tab, Log on as Local System account, and check "Allow service to interact with desktop".

Having windows that run as SYSTEM on a user desktop is a security issue, you should really use some other form of IPC (If all you need to do is notify the service without providing any other data, a (global) named event should be enough)
If on the other hand you want to catch notifications from windows itself about device changes, power and session events etc you don't do that with messages when you are running as a service, you get those events in your HandlerEx

Who's sending the broadcast? Unless the component sending the broadcast is running as Local System, it does not have the privilege to send window messages to window handles in different sessions.
Since all Windows Services (since Vista) run in Session 0, and almost all other components run in Session >=1, most probably that's why you are not receiving the broadcast.

Related

How can I run my application or some specific methods in background in windows phone

I want to run my application in background when i click on windows button.
Basically I have some methods of XMPP and when I goes to background it changes its status and presence from online to offline. I want this to be run in background.
Just because of the status is offline I am not able to receive any toast notification from XMPP.
If any one has idea about XMPP then please help to resolve this as well.
Any help will be much appreciated.
Thanks,
Nishant
You cannot make your app run in the background. I think that other IM apps use a push mechanism. So you need a server, when you app is exited, you tell the server to make the user seem still online and when a message arrives for the user, you send a push notification to the device. Whne the user taps the push notifictaion popup, your app will be started.
On Windows Phone "normal" apps cannot run continuous in background. XMPP normally requires a persistent long living TCP/IP connection during your complete session.
There are different ways to solve this problem:
1. create a app which can run in background, e.g a location tracking app or voice app
Log off when your app goes in background, you will not receive any message until your login in foreground.
Log off when your app is in background and also use a background service which log on in the interval of eg. 30 minutes and checks for new messages. But that's far away from being realtime and the idea of XMPP ;-)
Use a combination of XMPP and Push messages. XMPP while you are in foreground and Push when you are in background.
create a proxy between your app and the XMPP server and use Push. This means your app does not create the XMPP connection iself. Your app tells only your "proxy server" to login user X now. Your "proxy server" creates the XMPP connection and it can stay there 24/7 connected, doesn't matter whether your app is in background or not. Your app can communicate with your "XMPP proxy" over push or any other protocol choose.
Which solution your choose depends on your unique requirements. For chat apps like WhatsApp a background service is normally not appropriate because your messages are delayed for up to 30 minutes and your are not available while the background service does not run. While for other business apps this may be fine.

Receive event before Windows enters standby or hibernate using Win32 API

I'm working on a small chat application written in C++/Qt. My users are complaining that the connection is not shut down gracefully when they are closing the laptop lid and the computer enters standby.
Is there a Win32 hook available that is called when Windows is about to enter standby?
WM_POWERBROADCAST
Reimplement QCoreApplication::winEventFilter in your application to handle Windows standby events.

Detect shutdown as SYSTEM user

I have an application that is started by a service. The application has no User Interface, it contains a DataModule and a TMyApplication implementation that calls Forms.Application.HandleMessage in a loop (like SvcMgr.TServiceApplication). I hooked the MainWindow to log any messages the hidden window of Forms.Application receives.
If I manually start the application so it runs on my useraccount, I receive WM_QUERYENDSESSION and WM_ENDSESSION messages on the hidden window of Forms.Application when logging off/shutting down.
If I start my application using the service, the application runs under the SYSTEM account. When running under the system account I receive only one message, $0000001A (WM_WININICHANGE?), at systemshutdown before my application is forcefully terminated by Windows. So no WM_QUERYENDSESSION and WM_ENDSESSION messages.
How can I detect a Windows shutdown on a SYSTEM account and close my application gracefully?
Have your service notify your sub-application.
Here's some information about how the service control manager notifies your service:
http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/063cef3a-de94-44d5-8f2e-4e63c3cfdee8
Do a FindWindow, and PostMessage(hwnd, WM_ENDSESSION) yourself.

Is it possible to send a growl message to another user on the same computer on OSX?

My app currently uses growl to send the occasional message to the user, which works great when I am developing it. But once it is run as a in production, as a system-level Launch Daemon under a different user, the growl messages no longer appear.
So, the question: Is it possible to send a growl message to another user on the same computer on OSX?
Maybe you can send the message via the network (http://growl.info/documentation/developer/protocol.php) to localhost/127.0.0.1. But i can't find a hint in the docs to target a special user.

Are there special considerations for a windows service to send messages to user windows?

I have to write a Windows Service application (no GUI) that will monitor an event, and if it occurs will send a standard windows message to an application. The handle of the application will be given to the service by a DLL which is then unloaded, so a windows message is the way we wish to use.
The question though is whether the service needs to do anything special to use SendMessage to the window handle, given that it might be on a different screen or something in Vista. Is this possible, and if so, what do I have to do please?
User Interface Privilege Isolation (UIPI):
Microsoft Windows Vista and later.
Message sending is subject to User
Interface Privilege Isolation (UIPI).
The thread of a process can send
messages only to message queues of
threads in processes of lesser or
equal integrity level.
Source
You can read about User Interface Privilege Isolation (UIPI) here.
To get around this you can set uiAccess to true in your manifest file. You also have to make sure your application is signed using authenticode with a certificate from a signing authority such as VeriSign. This can get pretty expensive.
Session 0 isolation:
It is also my belief that you can't call SendMessage across sessions. So if you have a service running in session 0 you need to find another means to communicate with your process that would be running in a session > 0. Example: via pipe.
In Windows Vista, Windows 2008 Server and later all services run in session 0, and all applications that you start run in session > 0. This is called session 0 isolation. Here is a good document that has information all about session 0 isolation.
If you don't have access to the source of the program you want to send messages to, you could get around this by making an application that communicates with your service and acts as a proxy to relay the message to the application in its same session.
Overall:
If you develop your application on pre-Vista and it works fine. There is a very high chance it will be broken in Vista.

Resources