IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

modifier un service


Sujet :

VB 6 et antérieur

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Décembre 2005
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 17
    Par défaut modifier un service
    Bonjour,

    Je cherche à pouvoir modifier le mode de démarrage d'un service, mais, la fonction "ChangeServiceConfig" ne veut pas faire la modif souhaitée.... :-(

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    Private 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_BOOT_START = &H0
    Private Const SERVICE_SYSTEM_START = &H1
    Private Const SERVICE_AUTO_START = &H2
    Private Const SERVICE_DEMAND_START = &H3
    Private Const SERVICE_DISABLED = &H4
    Private Const SERVICE_NO_CHANGE = &HFFFFFFFF
     
    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)
     
     
    'ouverture de la console des services
    Public Declare Function OpenSCManager Lib "ADVAPI32.DLL" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
    'ouverture d'un service
    Public Declare Function OpenService Lib "ADVAPI32.DLL" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
    'modification des paramètres d'un service
    Public Declare Function ChangeServiceConfig Lib "ADVAPI32.DLL" Alias "ChangeServiceConfigA" (ByVal hService As Long, ByVal dwServiceType As Long, ByVal dwStartType As Long, ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, ByVal lpLoadOrderGroup As String, lpdwTagId As Long, ByVal lpDependencies As String, ByVal lpServiceStartName As String, ByVal lpPassword As String, ByVal lpDisplayName As String) As Long
    'fermeture d'un handle
    Declare Function CloseServiceHandle Lib "ADVAPI32.DLL" (ByVal hSCObject As Long) As Long
     
    Public Function modifService()
    Dim scManager As Long
    Dim service As Long
    Dim ret As Variant
     
        scManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_ALL_ACCESS)
        service = OpenService(scManager, "Aconvert", SERVICE_CHANGE_CONFIG)
     
        MsgBox ChangeServiceConfig(service, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, vbNull, vbNull, vbNull, vbNull, vbNull, vbNull, vbNull)
     
        CloseServiceHandle service
        CloseServiceHandle scManager
    End Function
    Si quelqu'un peut me donner un p'tit coup de main........
    Merci d'avance :-)

  2. #2
    Expert confirmé
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Par défaut
    essaie :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    MsgBox ChangeServiceConfig(service, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, vbNull, vbNull,  ByVal 0&, vbNull, vbNull, vbNull, vbNull

  3. #3
    Membre averti
    Inscrit en
    Décembre 2005
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 17
    Par défaut
    Et non, toujours pareil....

    J'en suis à ce niveau :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    'ouverture de la console des services
    Public Declare Function OpenSCManager Lib "ADVAPI32.DLL" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
    'ouverture d'un service
    Public Declare Function OpenService Lib "ADVAPI32.DLL" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
    'modification des paramètres d'un service
    Public Declare Function ChangeServiceConfig Lib "ADVAPI32.DLL" Alias "ChangeServiceConfigA" (ByVal hService As Long, ByVal dwServiceType As Long, ByVal dwStartType As Long, ByVal dwErrorControl As Long, ByVal lpBinaryPathName As String, ByVal lpLoadOrderGroup As String, lpdwTagId As Long, ByVal lpDependencies As String, ByVal lpServiceStartName As String, ByVal lpPassword As String, ByVal lpDisplayName As String) As Long
    Public Declare Function ChangeServiceConfig2 Lib "ADVAPI32.DLL" Alias "ChangeServiceConfigB" (ByVal hService As Long, ByVal dwInfoLevel As Long, lpInfo As Long) As Long
    'fermeture d'un handle
    Declare Function CloseServiceHandle Lib "ADVAPI32.DLL" (ByVal hSCObject As Long) As Long
     
    Public Function modifService()
    Dim scManager As Long
    Dim service As Long
    Dim ret As Variant
     
        scManager = OpenSCManager(vbNullString, vbNullString, SC_MANAGER_ALL_ACCESS)
        service = OpenService(scManager, "Aconvert", SERVICE_CHANGE_CONFIG)
     
        MsgBox ChangeServiceConfig(service, SERVICE_NO_CHANGE, SERVICE_AUTO_START, SERVICE_NO_CHANGE, vbNull, vbNull, ByVal 0&, vbNull, vbNull, vbNull, vbNull)
     
        CloseServiceHandle service
        CloseServiceHandle scManager    
     
    End Function
    [Balises de code rajoutées par Thierry AIM, Merci d'y penser la prochaine fois]

  4. #4
    Expert confirmé
    Avatar de ThierryAIM
    Homme Profil pro
    Inscrit en
    Septembre 2002
    Messages
    3 673
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Septembre 2002
    Messages : 3 673
    Par défaut
    verifie :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    service = OpenService(scManager, "Aconvert", SERVICE_CHANGE_CONFIG)
    if service=0 then MsgBox Err.LastDllError
    soit le service n'exite pas, soit c'est pas le bon nom

  5. #5
    Membre averti
    Inscrit en
    Décembre 2005
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 17
    Par défaut
    le scManager => ok, retour d'une valeur, pour le service, pareil, retour d'une valeur.

    Par contre le retour de la fonction "ChangeServiceConfig" me retourne 1057.

  6. #6
    Membre averti
    Inscrit en
    Décembre 2005
    Messages
    17
    Détails du profil
    Informations forums :
    Inscription : Décembre 2005
    Messages : 17
    Par défaut
    Enfin !!!!! ca marche, pour ceux que ça interresse, voici la solution (assezz simple en fait....)

    faire référence à "Microsoft WMI Scripting"

    puis
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Dim ServiceObject As SWbemObject
    Dim Locator As SWbemLocator
    Dim services As SWbemServices
     
    Set Locator = New SWbemLocator
    Set services = Locator.ConnectServer("")
    Set ServiceObject = services.Get("Win32_Service='Aconvert'")
     
       MsgBox ServiceObject.changestartmode("Automatic") ' ou Boot, System, Manual, Disabled
     
    Et hop, service modifier.....
    [/code]

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [C#] Modifier un service windows
    Par Nanais19 dans le forum Services Windows
    Réponses: 1
    Dernier message: 18/10/2011, 15h36
  2. Réponses: 0
    Dernier message: 17/02/2011, 11h02
  3. Modifier ria services quand mise a jour d' entité
    Par trouffiondesiles dans le forum Silverlight
    Réponses: 7
    Dernier message: 16/12/2010, 10h44
  4. Débuger (et modifier) un service WCF hébergé sous IIS
    Par Etanne dans le forum Windows Communication Foundation
    Réponses: 0
    Dernier message: 15/03/2010, 11h44
  5. Comment modifier le service onames en 9.2
    Par fmoriet dans le forum Administration
    Réponses: 6
    Dernier message: 25/09/2007, 09h29

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo