|
Trouver une ressource
Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !
Sujet : NT Service (Urgent) [ Archives Visual Basic / Système ] (nramel)
Informations & options pour cette discussion
|
samedi 20 avril 2002 à 10:39:44 |
NT Service (Urgent)

nramel
|
Bonjour, Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB. Merci d'avance Nicolas
|
|
|
|
lundi 29 avril 2002 à 01:09:37 |
Re : NT Service (Urgent)

Derrick soft
|
Bonsoir,
' Installation du service ' MonService.exe install ' Désinstallation du service ' MonService.exe uninstall
' Après avoir installé le service, vous pouvez le configurer : ' Panneau de configuration, Services, Cliquez sur votre service, puis démarrage
Sub Main()
Dim hSCManager As Long Dim hService As Long Dim ServiceTableEntry As SERVICE_TABLE_ENTRY Dim B As Boolean Dim cmd As String Dim U As Long
cmd = Trim(LCase(Command())) Select Case cmd
Case "install"
' Installe le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = CreateService(hSCManager, SERVICE_NAME, _ SERVICE_NAME, SERVICE_ALL_ACCESS, _ SERVICE_WIN32_OWN_PROCESS, _ SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _ App.Path & "\" & App.EXEName, vbNullString, _ vbNullString, vbNullString, vbNullString, _ vbNullString) CloseServiceHandle hService CloseServiceHandle hSCManager
Case "uninstall"
' Désinstalle le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = OpenService(hSCManager, SERVICE_NAME, _ SERVICE_ALL_ACCESS) DeleteService hService CloseServiceHandle hService CloseServiceHandle hSCManager
Case Else
'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
hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, _ AddressOf Handler) ServiceStatus.dwCurrentState = SERVICE_START_PENDING B = SetServiceStatus(hServiceStatus, ServiceStatus)
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)
End Sub
Function FncPtr(ByVal fnp As Long) As Long
FncPtr = fnp End Function
N'oubliez pas les déclarations :
Private Const SERVICE_WIN32_OWN_PROCESS = &H10& Private Const SERVICE_WIN32_SHARE_PROCESS = &H20& Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _ SERVICE_WIN32_SHARE_PROCESS
Private Const SERVICE_ACCEPT_STOP = &H1 Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
Private Const SC_MANAGER_CONNECT = &H1 Private Const SC_MANAGER_CREATE_SERVICE = &H2 Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4 Private Const SC_MANAGER_LOCK = &H8 Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10 Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const SERVICE_QUERY_CONFIG = &H1 Private Const SERVICE_CHANGE_CONFIG = &H2 Private Const SERVICE_QUERY_STATUS = &H4 Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8 Private Const SERVICE_START = &H10 Private Const SERVICE_STOP = &H20 Private Const SERVICE_PAUSE_CONTINUE = &H40 Private Const SERVICE_INTERROGATE = &H80 Private Const SERVICE_USER_DEFINED_CONTROL = &H100 Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ SERVICE_QUERY_CONFIG Or _ SERVICE_CHANGE_CONFIG Or _ SERVICE_QUERY_STATUS Or _ SERVICE_ENUMERATE_DEPENDENTS Or _ SERVICE_START Or _ SERVICE_STOP Or _ SERVICE_INTERROGATE Or _ SERVICE_USER_DEFINED_CONTROL)
Private Const SERVICE_DEMAND_START As Long = &H3
Private Const SERVICE_ERROR_NORMAL As Long = &H1
Private Enum SERVICE_CONTROL
SERVICE_CONTROL_STOP = &H1 SERVICE_CONTROL_PAUSE = &H2 SERVICE_CONTROL_CONTINUE = &H3 SERVICE_CONTROL_INTERROGATE = &H4 SERVICE_CONTROL_SHUTDOWN = &H5
End Enum
Private Enum SERVICE_STATE
SERVICE_STOPPED = &H1 SERVICE_START_PENDING = &H2 SERVICE_STOP_PENDING = &H3 SERVICE_RUNNING = &H4 SERVICE_CONTINUE_PENDING = &H5 SERVICE_PAUSE_PENDING = &H6 SERVICE_PAUSED = &H7 End Enum
Private Type SERVICE_TABLE_ENTRY
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
------------------------------- Réponse au message : -------------------------------
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
Merci d'avance
Nicolas
|
|
|
|
mercredi 22 mai 2002 à 16:30:51 |
Re : NT Service (Urgent)

era
|
il marche pas ce code il lance pas l appli il ne fait ke creer un service
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonsoir,
' Installation du service ' MonService.exe install ' Désinstallation du service ' MonService.exe uninstall
' Après avoir installé le service, vous pouvez le configurer : ' Panneau de configuration, Services, Cliquez sur votre service, puis démarrage
Sub Main()
Dim hSCManager As Long Dim hService As Long Dim ServiceTableEntry As SERVICE_TABLE_ENTRY Dim B As Boolean Dim cmd As String Dim U As Long
cmd = Trim(LCase(Command())) Select Case cmd
Case "install"
' Installe le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = CreateService(hSCManager, SERVICE_NAME, _ SERVICE_NAME, SERVICE_ALL_ACCESS, _ SERVICE_WIN32_OWN_PROCESS, _ SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _ App.Path & "\" & App.EXEName, vbNullString, _ vbNullString, vbNullString, vbNullString, _ vbNullString) CloseServiceHandle hService CloseServiceHandle hSCManager
Case "uninstall"
' Désinstalle le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = OpenService(hSCManager, SERVICE_NAME, _ SERVICE_ALL_ACCESS) DeleteService hService CloseServiceHandle hService CloseServiceHandle hSCManager
Case Else
'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
hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, _ AddressOf Handler) ServiceStatus.dwCurrentState = SERVICE_START_PENDING B = SetServiceStatus(hServiceStatus, ServiceStatus)
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)
End Sub
Function FncPtr(ByVal fnp As Long) As Long
FncPtr = fnp End Function
N'oubliez pas les déclarations :
Private Const SERVICE_WIN32_OWN_PROCESS = &H10& Private Const SERVICE_WIN32_SHARE_PROCESS = &H20& Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _ SERVICE_WIN32_SHARE_PROCESS
Private Const SERVICE_ACCEPT_STOP = &H1 Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
Private Const SC_MANAGER_CONNECT = &H1 Private Const SC_MANAGER_CREATE_SERVICE = &H2 Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4 Private Const SC_MANAGER_LOCK = &H8 Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10 Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const SERVICE_QUERY_CONFIG = &H1 Private Const SERVICE_CHANGE_CONFIG = &H2 Private Const SERVICE_QUERY_STATUS = &H4 Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8 Private Const SERVICE_START = &H10 Private Const SERVICE_STOP = &H20 Private Const SERVICE_PAUSE_CONTINUE = &H40 Private Const SERVICE_INTERROGATE = &H80 Private Const SERVICE_USER_DEFINED_CONTROL = &H100 Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ SERVICE_QUERY_CONFIG Or _ SERVICE_CHANGE_CONFIG Or _ SERVICE_QUERY_STATUS Or _ SERVICE_ENUMERATE_DEPENDENTS Or _ SERVICE_START Or _ SERVICE_STOP Or _ SERVICE_INTERROGATE Or _ SERVICE_USER_DEFINED_CONTROL)
Private Const SERVICE_DEMAND_START As Long = &H3
Private Const SERVICE_ERROR_NORMAL As Long = &H1
Private Enum SERVICE_CONTROL
SERVICE_CONTROL_STOP = &H1 SERVICE_CONTROL_PAUSE = &H2 SERVICE_CONTROL_CONTINUE = &H3 SERVICE_CONTROL_INTERROGATE = &H4 SERVICE_CONTROL_SHUTDOWN = &H5
End Enum
Private Enum SERVICE_STATE
SERVICE_STOPPED = &H1 SERVICE_START_PENDING = &H2 SERVICE_STOP_PENDING = &H3 SERVICE_RUNNING = &H4 SERVICE_CONTINUE_PENDING = &H5 SERVICE_PAUSE_PENDING = &H6 SERVICE_PAUSED = &H7 End Enum
Private Type SERVICE_TABLE_ENTRY
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
------------------------------- Réponse au message : -------------------------------
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
Merci d'avance
Nicolas
|
|
|
|
mercredi 22 mai 2002 à 19:31:10 |
Re : NT Service (Urgent)

Derrick soft
|
Bonjour,
Dans le sujet du message il est demander comment créer un service NT et pas le reste!
Cordialement
Stéphane Maillard
------------------------------- Réponse au message : -------------------------------
il marche pas ce code il lance pas l appli il ne fait ke creer un service
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonsoir,
' Installation du service ' MonService.exe install ' Désinstallation du service ' MonService.exe uninstall
' Après avoir installé le service, vous pouvez le configurer : ' Panneau de configuration, Services, Cliquez sur votre service, puis démarrage
Sub Main()
Dim hSCManager As Long Dim hService As Long Dim ServiceTableEntry As SERVICE_TABLE_ENTRY Dim B As Boolean Dim cmd As String Dim U As Long
cmd = Trim(LCase(Command())) Select Case cmd
Case "install"
' Installe le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = CreateService(hSCManager, SERVICE_NAME, _ SERVICE_NAME, SERVICE_ALL_ACCESS, _ SERVICE_WIN32_OWN_PROCESS, _ SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _ App.Path & "\" & App.EXEName, vbNullString, _ vbNullString, vbNullString, vbNullString, _ vbNullString) CloseServiceHandle hService CloseServiceHandle hSCManager
Case "uninstall"
' Désinstalle le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = OpenService(hSCManager, SERVICE_NAME, _ SERVICE_ALL_ACCESS) DeleteService hService CloseServiceHandle hService CloseServiceHandle hSCManager
Case Else
'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
hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, _ AddressOf Handler) ServiceStatus.dwCurrentState = SERVICE_START_PENDING B = SetServiceStatus(hServiceStatus, ServiceStatus)
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)
End Sub
Function FncPtr(ByVal fnp As Long) As Long
FncPtr = fnp End Function
N'oubliez pas les déclarations :
Private Const SERVICE_WIN32_OWN_PROCESS = &H10& Private Const SERVICE_WIN32_SHARE_PROCESS = &H20& Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _ SERVICE_WIN32_SHARE_PROCESS
Private Const SERVICE_ACCEPT_STOP = &H1 Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
Private Const SC_MANAGER_CONNECT = &H1 Private Const SC_MANAGER_CREATE_SERVICE = &H2 Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4 Private Const SC_MANAGER_LOCK = &H8 Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10 Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const SERVICE_QUERY_CONFIG = &H1 Private Const SERVICE_CHANGE_CONFIG = &H2 Private Const SERVICE_QUERY_STATUS = &H4 Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8 Private Const SERVICE_START = &H10 Private Const SERVICE_STOP = &H20 Private Const SERVICE_PAUSE_CONTINUE = &H40 Private Const SERVICE_INTERROGATE = &H80 Private Const SERVICE_USER_DEFINED_CONTROL = &H100 Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ SERVICE_QUERY_CONFIG Or _ SERVICE_CHANGE_CONFIG Or _ SERVICE_QUERY_STATUS Or _ SERVICE_ENUMERATE_DEPENDENTS Or _ SERVICE_START Or _ SERVICE_STOP Or _ SERVICE_INTERROGATE Or _ SERVICE_USER_DEFINED_CONTROL)
Private Const SERVICE_DEMAND_START As Long = &H3
Private Const SERVICE_ERROR_NORMAL As Long = &H1
Private Enum SERVICE_CONTROL
SERVICE_CONTROL_STOP = &H1 SERVICE_CONTROL_PAUSE = &H2 SERVICE_CONTROL_CONTINUE = &H3 SERVICE_CONTROL_INTERROGATE = &H4 SERVICE_CONTROL_SHUTDOWN = &H5
End Enum
Private Enum SERVICE_STATE
SERVICE_STOPPED = &H1 SERVICE_START_PENDING = &H2 SERVICE_STOP_PENDING = &H3 SERVICE_RUNNING = &H4 SERVICE_CONTINUE_PENDING = &H5 SERVICE_PAUSE_PENDING = &H6 SERVICE_PAUSED = &H7 End Enum
Private Type SERVICE_TABLE_ENTRY
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
------------------------------- Réponse au message : -------------------------------
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
Merci d'avance
Nicolas
|
|
|
|
mercredi 22 mai 2002 à 19:33:42 |
Re : NT Service (Urgent)

era
|
je veux bien derrick mais a quoi sert de creer un service si on ne peut pas lancer d appli
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonjour,
Dans le sujet du message il est demander comment créer un service NT et pas le reste!
Cordialement
Stéphane Maillard
------------------------------- Réponse au message : -------------------------------
il marche pas ce code il lance pas l appli il ne fait ke creer un service
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonsoir,
' Installation du service ' MonService.exe install ' Désinstallation du service ' MonService.exe uninstall
' Après avoir installé le service, vous pouvez le configurer : ' Panneau de configuration, Services, Cliquez sur votre service, puis démarrage
Sub Main()
Dim hSCManager As Long Dim hService As Long Dim ServiceTableEntry As SERVICE_TABLE_ENTRY Dim B As Boolean Dim cmd As String Dim U As Long
cmd = Trim(LCase(Command())) Select Case cmd
Case "install"
' Installe le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = CreateService(hSCManager, SERVICE_NAME, _ SERVICE_NAME, SERVICE_ALL_ACCESS, _ SERVICE_WIN32_OWN_PROCESS, _ SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _ App.Path & "\" & App.EXEName, vbNullString, _ vbNullString, vbNullString, vbNullString, _ vbNullString) CloseServiceHandle hService CloseServiceHandle hSCManager
Case "uninstall"
' Désinstalle le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = OpenService(hSCManager, SERVICE_NAME, _ SERVICE_ALL_ACCESS) DeleteService hService CloseServiceHandle hService CloseServiceHandle hSCManager
Case Else
'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
hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, _ AddressOf Handler) ServiceStatus.dwCurrentState = SERVICE_START_PENDING B = SetServiceStatus(hServiceStatus, ServiceStatus)
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)
End Sub
Function FncPtr(ByVal fnp As Long) As Long
FncPtr = fnp End Function
N'oubliez pas les déclarations :
Private Const SERVICE_WIN32_OWN_PROCESS = &H10& Private Const SERVICE_WIN32_SHARE_PROCESS = &H20& Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _ SERVICE_WIN32_SHARE_PROCESS
Private Const SERVICE_ACCEPT_STOP = &H1 Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
Private Const SC_MANAGER_CONNECT = &H1 Private Const SC_MANAGER_CREATE_SERVICE = &H2 Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4 Private Const SC_MANAGER_LOCK = &H8 Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10 Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const SERVICE_QUERY_CONFIG = &H1 Private Const SERVICE_CHANGE_CONFIG = &H2 Private Const SERVICE_QUERY_STATUS = &H4 Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8 Private Const SERVICE_START = &H10 Private Const SERVICE_STOP = &H20 Private Const SERVICE_PAUSE_CONTINUE = &H40 Private Const SERVICE_INTERROGATE = &H80 Private Const SERVICE_USER_DEFINED_CONTROL = &H100 Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ SERVICE_QUERY_CONFIG Or _ SERVICE_CHANGE_CONFIG Or _ SERVICE_QUERY_STATUS Or _ SERVICE_ENUMERATE_DEPENDENTS Or _ SERVICE_START Or _ SERVICE_STOP Or _ SERVICE_INTERROGATE Or _ SERVICE_USER_DEFINED_CONTROL)
Private Const SERVICE_DEMAND_START As Long = &H3
Private Const SERVICE_ERROR_NORMAL As Long = &H1
Private Enum SERVICE_CONTROL
SERVICE_CONTROL_STOP = &H1 SERVICE_CONTROL_PAUSE = &H2 SERVICE_CONTROL_CONTINUE = &H3 SERVICE_CONTROL_INTERROGATE = &H4 SERVICE_CONTROL_SHUTDOWN = &H5
End Enum
Private Enum SERVICE_STATE
SERVICE_STOPPED = &H1 SERVICE_START_PENDING = &H2 SERVICE_STOP_PENDING = &H3 SERVICE_RUNNING = &H4 SERVICE_CONTINUE_PENDING = &H5 SERVICE_PAUSE_PENDING = &H6 SERVICE_PAUSED = &H7 End Enum
Private Type SERVICE_TABLE_ENTRY
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
------------------------------- Réponse au message : -------------------------------
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
Merci d'avance
Nicolas
|
|
|
|
mercredi 22 mai 2002 à 19:42:42 |
Re : NT Service (Urgent)

Derrick soft
|
Re,
A partir de ce code vous pouvez lancer n'importe lequel de vos programmes, en mettant à false le ShowInTaskbar.
Cordialement
------------------------------- Réponse au message : -------------------------------
je veux bien derrick mais a quoi sert de creer un service si on ne peut pas lancer d appli
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonjour,
Dans le sujet du message il est demander comment créer un service NT et pas le reste!
Cordialement
Stéphane Maillard
------------------------------- Réponse au message : -------------------------------
il marche pas ce code il lance pas l appli il ne fait ke creer un service
Y a pas que $crosoft dans la vie...... Ebouda ^-[( ° ° )]-^
------------------------------- Réponse au message : -------------------------------
Bonsoir,
' Installation du service ' MonService.exe install ' Désinstallation du service ' MonService.exe uninstall
' Après avoir installé le service, vous pouvez le configurer : ' Panneau de configuration, Services, Cliquez sur votre service, puis démarrage
Sub Main()
Dim hSCManager As Long Dim hService As Long Dim ServiceTableEntry As SERVICE_TABLE_ENTRY Dim B As Boolean Dim cmd As String Dim U As Long
cmd = Trim(LCase(Command())) Select Case cmd
Case "install"
' Installe le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = CreateService(hSCManager, SERVICE_NAME, _ SERVICE_NAME, SERVICE_ALL_ACCESS, _ SERVICE_WIN32_OWN_PROCESS, _ SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, _ App.Path & "\" & App.EXEName, vbNullString, _ vbNullString, vbNullString, vbNullString, _ vbNullString) CloseServiceHandle hService CloseServiceHandle hSCManager
Case "uninstall"
' Désinstalle le Service hSCManager = OpenSCManager(vbNullString, vbNullString, _ SC_MANAGER_CREATE_SERVICE) hService = OpenService(hSCManager, SERVICE_NAME, _ SERVICE_ALL_ACCESS) DeleteService hService CloseServiceHandle hService CloseServiceHandle hSCManager
Case Else
'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
hServiceStatus = RegisterServiceCtrlHandler(SERVICE_NAME, _ AddressOf Handler) ServiceStatus.dwCurrentState = SERVICE_START_PENDING B = SetServiceStatus(hServiceStatus, ServiceStatus)
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)
End Sub
Function FncPtr(ByVal fnp As Long) As Long
FncPtr = fnp End Function
N'oubliez pas les déclarations :
Private Const SERVICE_WIN32_OWN_PROCESS = &H10& Private Const SERVICE_WIN32_SHARE_PROCESS = &H20& Private Const SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS + _ SERVICE_WIN32_SHARE_PROCESS
Private Const SERVICE_ACCEPT_STOP = &H1 Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_SHUTDOWN = &H4
Private Const SC_MANAGER_CONNECT = &H1 Private Const SC_MANAGER_CREATE_SERVICE = &H2 Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4 Private Const SC_MANAGER_LOCK = &H8 Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10 Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Public Const STANDARD_RIGHTS_REQUIRED = &HF0000 Private Const SERVICE_QUERY_CONFIG = &H1 Private Const SERVICE_CHANGE_CONFIG = &H2 Private Const SERVICE_QUERY_STATUS = &H4 Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8 Private Const SERVICE_START = &H10 Private Const SERVICE_STOP = &H20 Private Const SERVICE_PAUSE_CONTINUE = &H40 Private Const SERVICE_INTERROGATE = &H80 Private Const SERVICE_USER_DEFINED_CONTROL = &H100 Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _ SERVICE_QUERY_CONFIG Or _ SERVICE_CHANGE_CONFIG Or _ SERVICE_QUERY_STATUS Or _ SERVICE_ENUMERATE_DEPENDENTS Or _ SERVICE_START Or _ SERVICE_STOP Or _ SERVICE_INTERROGATE Or _ SERVICE_USER_DEFINED_CONTROL)
Private Const SERVICE_DEMAND_START As Long = &H3
Private Const SERVICE_ERROR_NORMAL As Long = &H1
Private Enum SERVICE_CONTROL
SERVICE_CONTROL_STOP = &H1 SERVICE_CONTROL_PAUSE = &H2 SERVICE_CONTROL_CONTINUE = &H3 SERVICE_CONTROL_INTERROGATE = &H4 SERVICE_CONTROL_SHUTDOWN = &H5
End Enum
Private Enum SERVICE_STATE
SERVICE_STOPPED = &H1 SERVICE_START_PENDING = &H2 SERVICE_STOP_PENDING = &H3 SERVICE_RUNNING = &H4 SERVICE_CONTINUE_PENDING = &H5 SERVICE_PAUSE_PENDING = &H6 SERVICE_PAUSED = &H7 End Enum
Private Type SERVICE_TABLE_ENTRY
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
------------------------------- Réponse au message : -------------------------------
Bonjour,
Est-ce quelqu'un aurrai un code source d'exemple de création de NT Service entièrement écrit en VB.
Merci d'avance
Nicolas
|
|
|
|
mercredi 22 mai 2002 à 21:19:56 |
Re : NT Service (Urgent)

era
|
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
comprends pas tout moi .
merci pour tes reponses
si kkun a des idees
|
|
|
Cette discussion est classé dans : urgent, nt, service
Répondre à ce message
Sujets en rapport avec ce message
Service NT URGENT [ par Marc88 ]
Marco88J'ai utiliser le code que l'on trouve partout sur le site pour créer un service sous VB6 , pas de probmème j'arrive à créer mons service et le
Arrêter/démarrer un service NT externe au programe [ par DavidT ]
Je souhaitepouvoir arrêter un service NT spécifique Comment faire à partir de VB pour arrêter ou démarrer un service listé dans la liste services Le s
Service NT [ par poleau ]
Je cherche à éxecuter un prog VB en tant que service sous NT4. L'installation du service se passe sans problème grâce aux nombreuses sources de ce sit
Probleme avec mon service serveur Windows NT [ par anspauldou ]
Salutj'ai besoin d'aide lorsque je lance l'exécution du service serveur sous mon windows nt workstation, il me renvoie un message disant : Memoire ins
Service NT + Word OLE + Impression [ par Loïc ]
J'ai créé un petit service en vb avec l'ActiveX fourni par microsoft dans la MSDN qui me permet de me connecter via OLE à WORD. Jusque là pas de probl
Service NT [ par Sna ]
Bonjour a tousvoila j'ai bien lu les messages concernant les services NTmalheureusement je n'arrive pas a trouver le probleme du lancement du service
Pb Reseau NT urgent [ par pirate75000 ]
Pb Reseau NT urgentJ'ai un programme qui doit enregistrer des fichiers sur un serveur NT, comment faire pour avoir la fentres qui permet de selectionn
Pb Reseau NT urgent [ par pirate75000 ]
Pb Reseau NT urgentJ'ai un programme qui doit enregistrer des fichiers sur un serveur NT, comment faire pour avoir la fentres qui permet de selectionn
Pb Reseau NT urgent [ par pirate75000 ]
Pb Reseau NT urgentJ'ai un programme qui doit enregistrer des fichiers sur un serveur NT, comment faire pour avoir la fentres qui permet de selectionn
TRES URGENT RECUPERER LE GROUPE USERS SUR NT [ par sebtik ]
Je dispose d une appli sur un serveur.Divers utilisateurs utilisent cette appli.Y a t il moyen de recuperer le groupe global NT auquel appartient chaq
Livres en rapport
|
Téléchargements
Logiciels à télécharger sur le même thème :
|