VB and VBA Users Source Code: Registering a process as a service
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Registering a process as a service
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, February 25, 2002
Hits:
1536
Category:
Windows API
Article:
The following code is a windows 9x version of how to register a process as a service. Note, does not work on NT. Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long Private Declare Function RegisterServiceProcess Lib "kernel32" (ByVal dwProcessID As Long, ByVal dwType As Long) As Long 'Purpose : Registers/unregisters a process as a service. 'Inputs : lProcessHwnd The process identifier ' bRegister If True registers the process as a service, else unregisters the process. 'Outputs : N/A 'Author : Andrew Baker (copyright www.vbusers.com) 'Date : 31/Jan/2002 'Notes : Windows 95 or newer (NOT Windows NT). ' A service process continues to run after the user logs off and is ' hidden from the CTRL-ALT-DEL program list. 'Revisions : Public Sub ProcessSetServiceState(lProcID As Long, bRegister As Boolean) Const RSP_SIMPLE_SERVICE = 1, RSP_UNREGISTER_SERVICE = 0 If bRegister Then Call RegisterServiceProcess(lProcID, RSP_SIMPLE_SERVICE) Else 'Unregister as service Call RegisterServiceProcess(lProcID, RSP_UNREGISTER_SERVICE) End If End Sub Private Sub Form_Load() Dim lProcID As Long 'Get the current process ID lProcID = GetCurrentProcessId() ProcessSetServiceState lProcID, True End Sub Private Sub Form_Unload(Cancel As Integer) Dim lProcID As Long 'Get the current process ID lProcID = GetCurrentProcessId() ProcessSetServiceState lProcID, False End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder