Using a Service Under Windows
Posted
by Elmue Elmue
on July 24th, 2003
This article was contributed by Elmue.

Environment: Windows NT/2000/XP
Description
This demo shows how to create, start, stop, and delete a service under Windows NT/2000/XP.
This program demonstrates the use of these API commands:
- OpenSCManager()
- CloseServiceHandle()
- CreateService()
- OpenService()
- SetServiceStatus()
- DeleteService()
- RegisterServiceCtrlHandler()
- StartServiceCtrlDispatcher()
- LPSERVICE_MAIN_FUNCTION
- LPHANDLER_FUNCTION
Try this demo with an Administrator Account and a normal User or Guest Account! This program logs all commands it receives and executes into the logfile C:\DemoService.txt.
This program is used in two modes:
- Service.exe (without parameters) runs the program with the GUI (see screenshot)
- Service.exe /Service runs it as a Service (Windows calls Service.exe with the "/Service" parameter if the already installed Service is started)
In a Service, it is not possible to set a normal Timer (SetTimer()) because the service does not own a window and can't receive Window Messages.
For demonstration, I set a waitable timer that writes every five seconds to the log file, even when no user is logged on.
Downloads
Download demo project - 10 KbDownload source - 15 Kb

Comments
Summary document shows you the proven info regarding gucci and ways in which it might have an affect on customers.
Posted by emeseesip on 05/07/2013 02:03amBasically The Most Thorough adidas Manual You Ever Read Otherwise Your Money Back [url=http://www.guccija.biz/]ã°ãã ããã°[/url] Geez, wonderful item. Your organization have to see adidas right away whilst it's still in stock ! [url=http://www.guccija.biz/]gucci ãã¼ã±ã¼ã¹[/url] nike assists everybody by adding many exceptional features and options. Its a unvaluable item for any fan of nike. [url=http://www.guccija.biz/]ã°ãã ã·ã§ã«ãã¼ããã°[/url] Third party statement unwraps Seven great new things surrounding nike that not a soul is discussing. [url=http://www.chanelja.biz/]ã·ã£ãã« ããã°[/url] This is why no one is bringing up adidas and consequently things one ought to begin doing today. [url=http://www.chanelja.biz/]chanel ããã°[/url] Different questions about adidas answered and consequently why you should definitely browse through each and every term of this specific report. [url=http://www.chanelja.biz/]è²¡å¸ chanel[/url] The essentials behind gucci which you may gain from getting started today.[url=http://www.nikeja.biz/]ãã¤ãã¹ãã¼ã«ã¼[/url] The best way to fully understand all that there is to find related to adidas in 5 basic steps.
Replyburberry femme pas cher
Posted by Acequeacila on 04/30/2013 05:58amBurberry Pas Cher burberry homme pas cher sac burberry pas cher sacoche burberry pas cher [url=http://burberry-femme-pas-cher28.webnode.fr/]burberry-femme-pas-cher28.webnode.fr[/url] , Chemise Burberry Pas Cher [url=http://burberryhomme2.webnode.fr/]burberryhomme2.webnode.fr[/url] , Burberry Pas Cher
ReplyOut of the ordinary article offers the run information for nike which experts claim a few buyers are aware of.
Posted by icoppyapedcap on 04/25/2013 01:07pmTarOsbVrxCvh [url=http://www.nikeyasuijp.com/]nike[/url]BqaAkbFpxGxu [url=http://www.nikeyasuijp.com/nike-air-force1ã¨ã¢ãã©ã¼ã¹1-c-14.html]ãã¤ã ããª[/url]IcwYhxRmhXam [url=http://www.nikeyasuijp.com/nike-air-maxã¨ã¢ããã¯ã¹-c-12.html]nike air max[/url]QfzTzqLmxIjc [url=http://www.nikeyasuijp.com/nike-air-jordanã¨ã¢-ã¸ã§ã¼ãã³-c-13.html]ãã¤ãã©ã³ãã³ã°[/url]DjqGgmJuuJle
ReplyDownload problems
Posted by noamshan on 12/15/2005 03:49amI can't download the zip files mentioned here. If I click on the link, I get to the site map page. Can anybody help or send them over?
ReplyHow to copy files to Network path from Service..?
Posted by rm_pkt on 04/09/2004 06:05amHi there! My Service application need to copy some files to a network path. How can I achive this.? I'm using VC++ 6 in WinodowsXP. Any idea would be appriciated. - muthu
ReplyThis is great!
Posted by Legacy on 12/03/2003 12:00amOriginally posted by: Mel
Just a couple minor changes and it's exactly what I want. I just added two edit boxes so that I can enter the name of the service and its display name.
Thanks for this program.
ReplyGive the man a break!
Posted by Legacy on 10/23/2003 12:00amOriginally posted by: Asconaga
I am sure when Linus Torvalds published Linux someone said "Why do you need to do this we already have Unix". I think the person has missed the point. You are trying to contribute and in my view with an excellent article. Thanks for your work, I and many others appreciate your time!
ReplyHow to create a service run under certain account instead of LocalSystem?
Posted by Legacy on 09/09/2003 12:00amOriginally posted by: hardywang
I tried pass user name and password to CreateService function, it doesn't work.
ReplyGreat Artice - excellent
Posted by Legacy on 08/27/2003 12:00amOriginally posted by: Leddy
Thanks for the great artice, whilst I acknowledge there are others doing similar things, its great having the whole thing in a neat win32 mfc app.
well done.
A controlling icon would be nice, but I am looking into that.
ReplyWhat's new
Posted by Legacy on 07/24/2003 12:00amOriginally posted by: peter desoza
There are already similar code available on codeguru, what's new you are presenting here?
Reply