In: Categories » Computers and technology » Microsoft OS family » How to Run your Own Program as a Service in Windows
|
Developing a Windows service program requires a fair bit of effort and programming skill. In addition to writing code to do whatever job the service has to do, you must add extra code that lets the service program communicate with the Windows Service Manager, so that the service can be started, stopped, and can communicate its status and dependencies to the manager. Still, in some cases it's nice to be able to have a program run when Windows boots up and have it stay running 24x7, whether you're logged on or not, and no matter what else is going on. And, in fact you can do this, using a utility program from the Windows 2000 Resource Kit that runs a program of your choice as if it were a service; the utility takes care of communicating with the Service manager, and runs your program using a specified command-line when the service manager starts it up. Your program can be a Windows application, command-line program, batch file, Windows Script Host script, database application, or a program written in another scripting language such as Perl. I've used this method to create a web server database back-end written in the FoxPro database language, and an interface to the SpamAssassin spam-filtering program written in Perl. A program that is to act as a service needs to function with no interaction from the keyboard, mouse, or screen. To communicate with the outside world, it can create and listen on network sockets, or it can scan a specified directory every so many seconds for the appearance of files. It should not run in an endless loop waiting for work to do, or it will slow performance of your computer. Instead, it should use Windows synchronization tools like Events, or at least it should "sleep" for periods of time in order not to consume any CPU power when it's idle. Test the program from the command line to be sure it works before trying to run it as a service. Then, when you are ready to install it as a service, follow these steps: Caution: Running a program as a service this way has some risks. In fact, the Windows AntiSpyware program reports the presence of Srvany as a risk every time it runs. If a hacker replaces the program that the service manager starts up, the bogus program will run with whatever privileges the service would have run with. You should follow the steps listed here to ensure that your service is safe from hacking.
Now, you should be able to start the service and press Ctrl+Alt+Del to see that the associated program appears in the Windows Task Manager's Processes display. If it doesn't, it may be exiting prematurely, or there may be a problem starting the service. In the latter case there should be a record in the Event log.
|
legal disclaimer
1) Our website is not responsible for the information contained by this article as well for any and all copyright infringements by authors and writers. E-articles is a free information resource. If you suspect this article for any copyright infringements, please read the Terms of service and contact us to investigate the problem.
2) The E-articles directory team is not responsible for inaccuracies, falsehoods, or any other types of misinformation this tutorial may contain and will not be liable for any loss or damage suffered by a user through the user's reliance on the information gained here. Please read the Terms of service
Useful tools and features
related articles
The CPU story is not over, however. The need for processors capable of handling far more than 4GB of memory has led to development of two competing 64-bit architectures. Intel developed and promoted a 64-bit architecture called IA-64 or Itanium, intended primarily for database and network server computers. Advanced Micro Devices also produced a 64-bit architecture, called x64 or AMD-64. Intel is now manufacturing chips that use the x64 instruction set. x64 processors typically yield better performance than Itanium running 32-bi...
2. Managing Startup Programs under Windows XP
Besides ensuring that your computer has adequate memory, one of the next best ways to improve your subjective experience of Windows' speed is to make the logon process faster. The logon process can be greatly slowed by large numbers of programs that are launched automatically upon logon; the desktop and Start menu don't respond until all of the login programs have been activated. Keeping the list of startup programs short is a constant struggle, however. To hide the fact that many common programs are poorly written and ...
3. How to Configure Automatic Updates in Windows XP
Automatic Updates is a mechanism with an awkwardly plural-sounding name by which Microsoft or corporate network managers distribute critical security updates to Windows users. Fixes sent by this means are considered so important for adequate security in the hostile Internet environment that Microsoft prefers that you configure it to download and install the updates, and if necessary even restart your computer without your being aware of it. There are four levels of Automatic Updates protection to which you can subscribe:...
4. MS DOS Versus PC DOS
With modern PCs having a very high level of standardization and compatibility, today it is easy to see how Microsoft can market complete packaged operating systems that will install and work unmodified on practically any PC you can purchase or build. Without the standardization and compatibility we have come to depend on, different specific "flavors" of a given operating system would be required for specific different hardware. That is exactly how things were back in the early '80s when the IBM PC was introduced. Many o...
To use Remote Desktop to reach your computer from the Internet, both the computer and your Internet connection must always be up and running. In addition, you must be able to make connections from the outside world to your computer, so there are additional requirements: If you use dial-up Internet service, you'll need someone at home to establish the connection before you can connect to your computer. If you use cable or DSL Internet service, you must either have a static IP address ass...
6. How to Update DirectX ~ Advantages
Although most Windows applications place fairly low demands on the display system, putting up fairly static displays and updating them relatively infrequently, interactive games and video displays are very graphics intensive. Game players pay big bucks for fps, or frames per second, which is a measure of how fast the hardware and software can generate new images as the scene changes and objects move. Under about 30fps, the image flickers and motion is noticeably jerky. Beyond 30fps, faster updates aren't noticeable, and the e...
7. Using Simple File Sharing in Windows
Although most home users are typically happy letting anyone at any computer read or modify any file, business users need to restrict access to files with payroll, personnel, and proprietary information. Windows XP and its predecessors, Windows NT and Windows 2000, were primarily designed for business use, so they require usernames and passwords for identification, and have a security system that lets computer owners restrict access to sensitive files on a user-by-user and file-by-file basis on each computer. Unfortunate...
8. The Evolution of Microsoft Windows ~ The Windows 9x Family
By the mid-1990s, processor power had increased and memory prices had decreased dramatically since Windows' original release. The Internet had also sprung onto the world stage, from an academic tool to an instrument of global communication and commerce. (You may recall that Windows 3.1 did not even include support for the TCP/IP network protocol used on the Internetyou had to purchase it from a third-party vendor.) Users' expectations likewise had grown with computers' capabilities, and desktop publishing, graphics editing, and...
9. How to install Windows and Installation Types
Deciding on the type of installation to perform is dictated by many factors, such as the following: Is there an operating system currently installed? If so, do you want to preserve settings and configurations, or start from scratch? Will the installation be performed interactively or remotely? How many computers are to be installed at a single time? Is your network arranged in a domain model using Active Directory? These are ...










