nramel
Messages postés8Date d'inscriptionjeudi 14 février 2002StatutMembreDernière intervention19 mai 2004
-
20 avril 2002 à 10:39
cs_era
Messages postés77Date d'inscriptionlundi 6 mai 2002StatutMembreDernière intervention 4 mai 2011
-
22 mai 2002 à 21:19
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
'Démarre le service
ServiceTableEntry.lpServiceName = SERVICE_NAME
ServiceTableEntry.lpServiceProc = FncPtr(AddressOf ServiceMain)
B = StartServiceCtrlDispatcher (ServiceTableEntry)
End Select
End Sub
Sub ServiceMain(ByVal dwArgc As Long, ByVal lpszArgv As Long)
Dim B As Boolean
Dim U As Long
Dim Z As Long
' Configuration Initiale
ServiceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS
ServiceStatus.dwCurrentState = SERVICE_START_PENDING
' Configuration des options accessibles depuis la boîte de dialogue des services
' Les contrôles que vous ne décrivez pas ci-dessous apparaitront en grisé
ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP _
Or SERVICE_ACCEPT_PAUSE_CONTINUE _
Or SERVICE_ACCEPT_SHUTDOWN
ServiceStatus.dwWin32ExitCode = 0
ServiceStatus.dwServiceSpecificExitCode = 0
ServiceStatus.dwCheckPoint = 0
ServiceStatus.dwWaitHint = 0
ServiceStatus.dwCurrentState = SERVICE_RUNNING
B = SetServiceStatus(hServiceStatus, ServiceStatus)
' Ici votre programme, ou l'appelle de votre fonction
'B = Mafonction(MesVariables)
'' Si une erreur se produit, vous pouvez utiliser ceci:
''Gestion_Erreur:
'' SetServerStatus SERVICE_STOP_PENDING
'' Clean up
'' SetServerStatus SERVICE_STOPPED
End Sub
Sub Handler(ByVal fdwControl As Long)
Dim B As Boolean
Dim U As Long
Select Case fdwControl
Case SERVICE_CONTROL_PAUSE
' Ce produit lorsque l'option Pause est demandée
ServiceStatus.dwCurrentState = SERVICE_PAUSED
Case SERVICE_CONTROL_CONTINUE
' Ce produit lorsque l'option Start est demandée
ServiceStatus.dwCurrentState = SERVICE_RUNNING
Case SERVICE_CONTROL_STOP
' Ce produit lorsque l'option Stop est demandée
ServiceStatus.dwWin32ExitCode = 0
ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING
ServiceStatus.dwCheckPoint = 0
ServiceStatus.dwWaitHint = 0 'Might want a time estimate
B = SetServiceStatus(hServiceStatus, ServiceStatus)
ServiceStatus.dwCurrentState = SERVICE_STOPPED
Case SERVICE_CONTROL_INTERROGATE
' Passe ici pour envoyer l'état actuel du service
Case Else
End Select
' envoi l'état actuel
B = SetServiceStatus(hServiceStatus, ServiceStatus)
lpServiceName As String
lpServiceProc As Long
lpServiceNameNull As Long
lpServiceProcNull As Long
End Type
Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Private Declare Function StartServiceCtrlDispatcher _
Lib "ADVAPI32.DLL" Alias "StartServiceCtrlDispatcherA" _
(lpServiceStartTable As SERVICE_TABLE_ENTRY) As Long
Private Declare Function RegisterServiceCtrlHandler _
Lib "ADVAPI32.DLL" Alias "RegisterServiceCtrlHandlerA" _
(ByVal lpServiceName As String, ByVal lpHandlerProc As Long) _
As Long
Private Declare Function SetServiceStatus _
Lib "ADVAPI32.DLL" (ByVal hServiceStatus As Long, _
lpServiceStatus As SERVICE_STATUS) As Long
Private Declare Function OpenSCManager _
Lib "ADVAPI32.DLL" Alias "OpenSCManagerA" _
(ByVal lpMachineName As String, ByVal lpDatabaseName As String, _
ByVal dwDesiredAccess As Long) As Long
Private Declare Function CreateService _
Lib "ADVAPI32.DLL" Alias "CreateServiceA" _
(ByVal hSCManager As Long, ByVal lpServiceName As String, _
ByVal lpDisplayName As String, ByVal dwDesiredAccess As Long, _
ByVal dwServiceType As Long, ByVal dwStartType As Long, _
ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, _
ByVal lpLoadOrderGroup As String, ByVal lpdwTagId As String, _
ByVal lpDependencies As String, ByVal lp As String, _
ByVal lpPassword As String) As Long
Private Declare Function DeleteService _
Lib "ADVAPI32.DLL" (ByVal hService As Long) As Long
Declare Function CloseServiceHandle _
Lib "ADVAPI32.DLL" (ByVal hSCObject As Long) As Long
Declare Function OpenService _
Lib "ADVAPI32.DLL" Alias "OpenServiceA" _
(ByVal hSCManager As Long, ByVal lpServiceName As String, _
ByVal dwDesiredAccess As Long) As Long
' Indiquez ici le nom du service, c'est lui qui apparait dans la boite de dialogue des services
Private Const SERVICE_NAME As String = "Mon Service NT"
Private hServiceStatus As Long
Private ServiceStatus As SERVICE_STATUS
cs_era
Messages postés77Date d'inscriptionlundi 6 mai 2002StatutMembreDernière intervention 4 mai 2011 22 mai 2002 à 21:19
je veux bien d ailleurs c'est ce que je fais
mais qd je lance le demarrage du service
il me renvoie une erreur
du coup je peux pas l arreter le mettre en pause
je ne peux que le demarrer