Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


NT System Service / MSDEV

Posted on 1999-07-07
Medium Priority
Last Modified: 2013-11-20

this isn't a pure MFC question, but this was the closest place to it I could find.

I am trying to create an NT System Service.  Since there doesn't seem to be any preset wizards to start this, I started an MFC regular application and then gutted all the files out of it.  I kept the application.cpp and stdafx stuff so I could have precompiled headers etc..  I have so far moved only main() into the application, compiled and run it.  It compiles fine but when I run it, it dies looking for winmain.

I did try starting this as a regular win32 application but it didn't offer me precompiled headers, and when I tried to add the precompiled headers, it refused to always compile the stdafx.cpp that I added first (if it needed recompiling).

My question has a few parts then.  

First, is this the best way to go about starting an NT Service application?

Second, if not, what is?  Should I start a console or win32 application and work from there?

Third, if I add precompiled headers to a project, how do I force it to check for update and compile it first always?  Do I change the name of it to like aaaaaaaa.cpp so it would be the first to compile?

any help in this would be appreciated.  Even some advice on where to look for more help would be greatly appreciated.

Question by:SD_Adept
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
LVL 86

Accepted Solution

jkr earned 300 total points
ID: 1309155
NT services are always console applications, as the SCM calls them passing the service's arguments using argc/argv.

The IMHO best (easiest) example on writing a service can be found at '' It's mainly a 'skeleton' RPC service, and it's loaded by starting it using the '-install' switch. The archive/sample name is 'rpcsvc'...

Ooops - i almost forgot to mention, you'll have to register with MSDN online to gain access, but that's for free - if you encounter problems viewing the page or downloading the sample, i could mail it to you (the MS site is always changing ;-)

>>if I add precompiled headers to a project, how do I force
>>it to check for update and compile it first always?  

The 'simplest' way would be to '#include' a central ceader file and change its timestamp - or even easier, use 'Rebuild all' or choose 'Clean...' from the right-click menu of your project in the tree view...

Feel free to ask if you encounter problems or have any further questions on this issue...

LVL 86

Expert Comment

ID: 1309156
Ooops, another useful link:

and "NT Service App Wizard" "A Class For Building An NT Service"

Author Comment

ID: 1309157
excellent.  That information led to a successful implementation of the service.  Thanks.

the information on rebuilding isn't correct though.  Doing a clean or rebuild all seems to make whatever is the first .cpp file (like adduser.cpp) to compile first instead of stdafx.cpp which needs to compile first (like it does in appwizard mfc programs).  This happens despite the fact that I've turned precompiled headers on and added stdafx.h and .cpp manually.  (owell).

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

LVL 86

Expert Comment

ID: 1309158
Hmm, 'Clean' should also delete the .pch files (or did I do that manually in my makefiles? ;-)

But altering the timestamp of 'stdafx.h' should also yield the desired result...

Author Comment

ID: 1309159
yea.  thats the thing though, how to alter the timestamp on stdafx.h during a clean.
LVL 86

Expert Comment

ID: 1309160
Get a Win32 'touch.exe' (e.g. from and add it to the makefile manually ;-)

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

721 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