• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

NT System Service / MSDEV

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.

  • 4
  • 2
1 Solution
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 'http://premium.microsoft.com/msdn/library/devprods/vs6/vc++/vcsample/vcsmprpcsvc.htm' 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...

Ooops, another useful link:



http://www.codeguru.com/system/nt_service_app_wizard.shtml "NT Service App Wizard"

http://www.codeguru.com/system/nt_service.shtml "A Class For Building An NT Service"
SD_AdeptAuthor Commented:
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).

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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...
SD_AdeptAuthor Commented:
yea.  thats the thing though, how to alter the timestamp on stdafx.h during a clean.
Get a Win32 'touch.exe' (e.g. from www.cygnus.com) and add it to the makefile manually ;-)
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now