je vien de trouver un exemple en vb :) demain j'essaie de le faire en asm :p
' Déclaration des fonctions API utilisées 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 OpenService Lib "advapi32.dll" Alias "OpenServiceA" ( _ ByVal hSCManager As Long, ByVal lpServiceName As String, _ ByVal dwDesiredAccess As Long) As Long Private Declare Function QueryServiceStatus Lib "advapi32.dll" (_ ByVal hService As Long, lpServiceStatus As SERVICE_STATUS) As Long Private Declare Function CloseServiceHandle Lib "advapi32.dll" ( _ ByVal hSCObject As Long) As Long
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
' Déclaration des constantes Private Const SERVICE_QUERY_STATUS = &H4
Private Const SERVICE_CONTINUE_PENDING = &H5 Private Const SERVICE_PAUSE_PENDING = &H6 Private Const SERVICE_PAUSED = &H7 Private Const SERVICE_RUNNING = &H4 Private Const SERVICE_START_PENDING = &H2 Private Const SERVICE_STOP_PENDING = &H3 Private Const SERVICE_STOPPED = &H1
Private Const SERVICE_ACCEPT_PAUSE_CONTINUE = &H2 Private Const SERVICE_ACCEPT_STOP = &H1
' Pour tester correctement l'exemple, créer un bouton 'cmdTest' ' et une zone de texte 'txtInfo' avec la propriété Multi-line à True.
Private Sub cmdTest_Click() Dim lgSCM As Long, lgSvc As Long, lgRet As Long Dim tySvc As SERVICE_STATUS ' Récupère un pointeur vers le contrôleur de service lgSCM = OpenSCManager(vbNullString, vbNullString, SERVICE_QUERY_STATUS) If (lgSCM <> 0) Then ' Ouvre le service "mysql" (à remplacer par un autre service ' pour tester l'exemple si mysql n'est pas installé sur votre machine) lgSvc = OpenService(lgSCM, "mysql", SERVICE_QUERY_STATUS) If (lgSvc <> 0) Then ' Lit l'état courant du service lgRet = QueryServiceStatus(lgSvc, tySvc) ' Affiche l'état Select Case tySvc.dwCurrentState Case SERVICE_CONTINUE_PENDING txtInfo.Text = "Reprise du service" Case SERVICE_PAUSE_PENDING txtInfo.Text = "Mise en pause" Case SERVICE_PAUSED txtInfo.Text = "En pause" Case SERVICE_RUNNING txtInfo.Text = "En fonctionnement" Case SERVICE_START_PENDING txtInfo.Text = "En cours de démarrage" Case SERVICE_STOP_PENDING txtInfo.Text = "En cours d'arrêt" Case SERVICE_STOPPED txtInfo.Text = "Arrêté" End Select ' Affiche les actions acceptées If (tySvc.dwControlsAccepted Or SERVICE_ACCEPT_PAUSE_CONTINUE) = _ tySvc.dwControlsAccepted Then txtInfo.Text = txtInfo.Text & vbCrLf & _ "Le service peut être mis en pause" End If If (tySvc.dwControlsAccepted Or SERVICE_ACCEPT_STOP) = _ tySvc.dwControlsAccepted Then txtInfo.Text = txtInfo.Text & vbCrLf & _ "Le service peut être arrêté" End If ' Libère le service lgRet = CloseServiceHandle(lgSvc) Else txtInfo.Text = "Pb sur OpenService!" End If ' Libère le contrôleur de service lgRet = CloseServiceHandle(lgSCM) Else txtInfo.Text = "Pb sur OpenSCManager!" End If End Sub
------------------------------- Réponse au message : -------------------------------
> en gros c'est un programme qui se lance avant meme que win soit totalement charger ( pas encore rentrer le login et mot de passe de win ) > ca peut etre un serveur ftp par exemple :) > si tu as win nt ( nt4-2000-xp (peut etre ca y est que sous les version pro) ) , va dans le panneau de config puis Outils d'administration , tu auras une icone services :p > ------------------------------- > Réponse au message : > ------------------------------- > > > > > désolé, c'est pas une réponse mais c'est quoi un "service" ? > > > > ------------------------------- > > Réponse au message : > > ------------------------------- > > > > > je cherche a ajouter un de mes programmes en tant que service sous win 2000 pro, > > > ca m'interesse aussi de savoir pour les autres OS ... > > > > > > merci d'avance ;) > > >
|