Create a new module and paste this code into it. Call the module basService.
If you have any questions, email us at help@codeoftheweek.com
'----------------------------------------------------------------------
'
' Module Name: basService
' Written By: C&D Programming Corp.
' Create Date: 2/2000
' Copyright: Copyright 2000 by C&D Programming Corp. Source
' code may not be reproduced except for use in a
' compiled executable. All rights reserved. If
' you would like to reprint any or all of this
' code please email us at info@codeoftheweek.com
'
'----------------------------------------------------------------------
Option Explicit
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function RegisterServiceProcess Lib "kernel32" _
(ByVal dwProcessId As Long, ByVal dwType As Long) As Long
Public Sub ServiceInstall()
Dim lPID As Long
Dim lRet As Long
lPID = GetCurrentProcessId
lRet = RegisterServiceProcess(lPID, 1) ' register as a process
If lRet = 0 Then
Err.Raise 5, "ServiceInstall", "Could not register as a service."
End If
End Sub
Public Sub ServiceUninstall()
Dim lPID As Long
Dim lRet As Long
lPID = GetCurrentProcessId
lRet = RegisterServiceProcess(lPID, 0) ' unregister as a process
If lRet = 0 Then
Err.Raise 5, "ServiceUninstall", "Could not unregister as a service."
End If
End Sub