Starting with the last issue the full Code of the Week issues will only be published every other week. All current subscribers which have purchased an annual subscription will still receive all 52 issues they paid for, it will just take two years to get them instead of one year. In the weeks between publication of Code of the Week we will usually send out shorter issues with more a tip type content (similar to the Ziff Davis VBTips ezine).
If you have any question about this publication change, please notify us at firstname.lastname@example.org
If you have any tips to contribute, email us at email@example.com. Be sure to include instructions and source code. For each tip received which gets published we will pay you $10 to $25 US Dollars.
In this issue we discuss how to run your application as a Windows Service (not an NT service).
If you have any questions about using this module, let us know at firstname.lastname@example.org
This module shows how to make your application run as a service. The main portion of these routines use the RegisterServiceProcess function to tell Windows that your application should stay active across Windows logins. It will also keep your application from showing up in the Ctrl-Alt-Del task listing. To use this module just call ServiceInstall at the start up of your application and ServiceUninstall at the end.
Microsoft describes this function as follows:
The RegisterServiceProcess Function
Applications started by the system using the RunServices and RunServicesOnce keys will close when the user selects Close all programs and log on as a different user from the Shutdown dialog box. By calling the RegisterServiceProcess function, a Win32-based application can prevent itself or any other Win32-based application from being closed when the user logs off. Win32-based applications registered in this manner close only when the system is shut down.
The application should provide for different users logging on at different times during its execution. The application can distinguish between a user logging off and the system shutting down by examining the lParam parameter of the WM_QUERYENDSESSION and WM_ENDSESSION messages. If the user shuts down the system, lParam is NULL. If the user logs off, lParam is set to ENDSESSION_LOGOFF.
Public Sub ServiceInstall()
Install the running application as a service. An error will be raised if this is unsuccessful.
Public Sub ServiceUninstall()
Uninstall the running application as a service. An error will be raised if this is unsuccessful.
This sample shows how to use the ServiceInstall and ServiceUninstall routine.
Public Sub Main() ServiceInstall frm.Show End Sub Public frm_Unload(Cancel as Integer) ServiceUninstall End Sub
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0125.html