Communicatng with an NT Service from a desktop application

Posted on 2000-01-29
Medium Priority
Last Modified: 2010-04-04
Hello Experts,
I have a little problem. When an NT service is running in the background of NT (not interacting with the desktop) I can send messages to it because the FindWindow function doesn't find the window when called from the desktop. Any ideas how to send such messages or how to use the FindWindow correctly? I'm convinced there must be some way. Thank you, I hope you know more than me.
Question by:jakubklos
  • 3
  • 2

Expert Comment

ID: 2410421
May be the best way to communicate with NT service is using pipes. This is fast and easy, and you don't have to switch Window Station to send messages.
LVL 20

Expert Comment

ID: 2410562
Here are some possibilites:

(1) Use named pipes (already suggested by okhoma) - CreatePipe
(2) Use memory mapped files (CreateFileMapping + MapViewOfFile) and events (CreateEvent, SetEvent, WaitForSingleObject)

But you can also keep with the current solution (by using a window and PostMessage/SendMessage). Then the problem is simply how can your main app know that window handle of the service? Easy:

(1) Your service could write it's window handle temporarily to the registry
(2) Use a create memory mapped file (CreateFileMapping + MapViewOfFile) and put the window handle there

If you need more explanation (or some code) about one of the suggestions, please ask.

Regards, Madshi.
LVL 20

Expert Comment

ID: 2410641
P.S: You can also try to use OpenWindowStation, OpenDesktop and EnumDesktopWindows to find that window handle.
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.


Author Comment

ID: 2412201
I see. I reckon the most professional way would be the pipes. However, I don't have any experience with that. Could you please, show me a piece of such code? Thank you guys.
LVL 20

Accepted Solution

Madshi earned 1600 total points
ID: 2412262
Here is an example source about how to use pipes:


Author Comment

ID: 2412361
Cool. That's it :). Thanks Madshi.


Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…
When you have multiple client accounts to manage, it often feels like there aren’t enough hours in the day. With too many applications to juggle, you can’t focus on your clients, much less your growing to-do list. But that doesn’t have to be the cas…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question