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

VBScript Discussion :

probleme de remonter de statut d'un service


Sujet :

VBScript

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 21
    Par défaut probleme de remonter de statut d'un service
    J'aimerais remonter le statut d'un service passé en argument dans DOS

    Je lance une commande dos qui execute mon script
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    yoyo.vbs "startservice" "Helpsvc"
    je stock la valeur de ces 2 arguments dans deux variables
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    ETAT_SERVICE = args(0)
    WIN_SERVICE1 = args(1)
    Jusqu'ici, tout va bien!!!

    Je voudrais en plus remonter l'éat du service passé en argument (WIN_SERVICE1) et socker le resultat dans une variable.

    Quelqu'un as t'il une idée?
    Merci d'avance

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 21
    Par défaut Question pour crack du vbs
    Salut a vous

    Voila une semaine que je galere sur ce put.. de code vbs. Je cherche une ame charitable (voir un developeur calé)pour me dire pourquoi et cela quelque soit l'etat du service, je rentre dans ma boucle 1.
    Merci d'avance


    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
     
    Create Shell object
    Dim objShell
     
    set objShell = CreateObject("Shell.Application")
    'Verify that the  service is running. If it isn't, then start it.
    If objShell.IsServiceRunning(WIN_SERVICE1) = TRUE then
    WScript.echo ("toto start")
    WScript.Sleep 10000
    objShell.ServiceStart (WIN_SERVICE1), TRUE
    WScript.Sleep 10000
     
     
    else if objShell.IsServiceRunning(WIN_SERVICE1) = FALSE Then
    WScript.echo ("ludo stop")
    WScript.Sleep 10000
    objShell.ServiceStop (WIN_SERVICE1), FALSE
    WScript.echo ("ludo start")
    WScript.Sleep 10000
    objShell.ServiceStart (WIN_SERVICE1), TRUE
    end if
     
    end if
    Si vous etes inspirée, faut pas hésiter

  3. #3
    Modérateur
    Avatar de AlainTech
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Mai 2005
    Messages
    4 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 71
    Localisation : Belgique

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Mai 2005
    Messages : 4 235
    Par défaut
    J'ai du mal à suivre...

    Cette discussion est-elle résolue, ou pas?

    Si oui, qu'est-ce qui va et qu'est-ce qui ne va pas?
    N'oubliez pas de cliquer sur quand vous avez obtenu ou trouvé vous-même la réponse à votre question.
    Si vous trouvez seul, pensez à poster votre solution. Elle peut servir à d'autres!
    Pensez aussi à voter pour les réponses qui vous ont aidés.
    ------------
    Je dois beaucoup de mes connaissances à mes erreurs!

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 21
    Par défaut Pas resolue
    Bonjour

    Non ce post n'est malheureusemetn pas resolu. Je n'arrive pas a recuperer la valeur d'un service (start ou stop) et a m'en service pour redemarer ou arreter suivant le statut remonté précedement.

    Cela vous parait t'il plus claire?

    Merci d'avance

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 21
    Par défaut Trop compliqué ou simplement pas faisable??
    Bonjour

    Personne ne peux définitivement pas m'aider sur le sujet?
    Peux t'on me dire juste si la méthode IsServiceRunning (service) accepte forcement une string en parametre ou si je peux lui passer une variable.


    Merci

  6. #6
    Expert éminent


    Profil pro
    Inscrit en
    Juin 2003
    Messages
    14 008
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 14 008
    Par défaut
    ben tu pourrai nous montrer le code en entier (avec l'affectation des arguments...) et la façon dont tu l'appelle... histoire de voir si tu as corrigé tes problémes d'ordre d'argument déjà signalés dans ton précédent post...

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    21
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 21
    Par défaut Cette fois, la totale pour que l'on puisse me venir en aide
    Bonjour

    Comme demandé, je poste mon code entier.
    En premier lieu, la lgne ede commande passée en dos
    C:\ludo.vbs "Startservice" 'helpsvc'

    En second, le code vbs, appelé en Dos
    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
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    ' ==========================================================================
    '  Nom             : ludo.vbs
    '  Objet           : Demarrage et Arret d un service systeme windows
    '  Environnements  : WINDOWS Y2K, Y2K3
    '  Parametre(s)    : Commande à lancer avec ses arguments
    '                    Lancer <Commande> [<arg1> <arg2> ...]
    '  Sortie          : retourne code erreur / Sortie si pas d'argument
    '  Codes retour    : 0 -> ok
    '                    1 -> erreur de syntaxe
    ===================================================================
    
    Const PID = "_"
    Const terminal = "not_a_TTY"
    Const gravite = "WARNING"
    Const valeur  = "OK"
    Const EVENT_SUCCESS = 0
    Private FSO, FicLog, FicLogBis
    Dim ETAT_SERVICE
    Dim WIN_SERVICE1
    
    
    'On instancie l'objet
    Set FSO = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
    
    'On instancie le fichier texte
    Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
    
    'On récupère les variables environnement
    
    Function getSystemVar(VarName)
        Dim wss, env
        Set wss = CreateObject("WScript.Shell")
        Set env = wss.environment("process")
        getSystemVar = env(VarName)
    End Function
    
    'On recupere une partie dela chaine de caractere
    
    resultat1 = Mid(getSystemVar("UNISON_SCHED"),2,3)
    resultat2 = Mid(getSystemVar("UNISON_SCHED"),7,3)
    resultat3 = Mid(getSystemVar("UNISON_SCHED"),5,3)
    resultat4 = Mid(getSystemVar("UNISON_JOB"),14,43)
    resultat5 = Mid(getSystemVar("USERNAME"),13.6)
    
    'Fonction remontant le service et son etat
    
    Dim objWMIService, objItem, objService
    Dim colListOfServices, strComputer, intSleep
    strComputer = "."
    intSleep = 5000
    
    ' NB strService is case sensitive.
    Set args  = Wscript.Arguments
    ETAT_SERVICE = args(0)
    WIN_SERVICE1 = args(1)
    
    message = "The service" & (WIN_SERVICE1)  & "is in state :" & (ETAT_SERVICE)
    
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colListOfServices = objWMIService.ExecQuery _
    ("Select * from Win32_Service Where Name ="_
    & WIN_SERVICE1 & " ")
    
    For Each objService in colListOfServices
    
    'Test du parametre de l'arret ou du démarrage du service
    
    If (ETAT_SERVICE) <> "Startservice" and (ETAT_SERVICE) <>"Stopservice" then
                    parametre = "Parametre invalide"
    
    'Creation dy fichier Log
    
                    If Err.Number = 0 Then
                            Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                            Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                            FtxtBis.writeline (parametre)
                            FtxtBis.Close
                            Set FtxtBis = Nothing
                            Ftxt.Close
                            Set Ftxt = Nothing
                    Else
                            Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
                            Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                            Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                            FtxtBis.writeline (parametre)
                            FtxtBis.Close 'Fermeture
                            Set FtxtBis = Nothing
                            Ftxt.Close
                            Set Ftxt = Nothing
                    End If
                    FSO.Close
                    WScript.Quit(1)
            End If
    
    
    
    
    
    '-------------------------------------------------------------------------------------------------------------------------
    If (ETAT_SERVICE) = "Startservice" Then
    
    	return = objService.StartService(WIN_SERVICE1)
    
     'Create Shell object
    Dim objShell
    Dim bIsRunning
    oShell = CreateObject("Shell.Application")
    
    'Verify that the  service is running. If it isn't, then start it.
     If NOT oShell.IsServiceRunning(WIN_SERVICE1) then
    WScript.echo ("toto start")
    WScript.Sleep 10000
    oShell.ServiceStart(WIN_SERVICE1)
    WScript.Sleep 10000
    
    else if oShell.IsServiceRunning(WIN_SERVICE1) Then
    WScript.echo ("ludo stop")
    WScript.Sleep 10000
    oShell.ServiceStop (WIN_SERVICE1)
    WScript.echo ("ludo start")
    WScript.Sleep 10000
    oShell.ServiceStart (WIN_SERVICE1)
    end if
    end if
    
    
    
    'Creation dy fichier Log
    
            If Err.Number = 0 Then
                    Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                    Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                    FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab & (message)
                    FtxtBis.Close
                    Set FtxtBis = Nothing
                    Ftxt.Close
                    Set Ftxt = Nothing
            Else
                    Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
                    Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                    Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                    FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab & (message)
                    FtxtBis.Close 'Fermeture
                    Set FtxtBis = Nothing
                    Ftxt.Close
                    Set Ftxt = Nothing
            End If
    FSO.Close
    
    'Ecrire dans l'event Log
    
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    objShell.LogEvent EVENT_SUCCESS, _
    (now) & chr(10) & "Les services" &  chr(1) & (strService) & "sur le serveur" & chr(1) & (getSystemVar ("COMPUTERNAME")) & chr(1) & "ont étés" & chr(1) & "par l'utilisateur" & chr(1) & (getSystemVar("username"))' & chr(1) & (sh.IsServiceRunning("Alerter"))	
    
    WScript.Quit(return)
    
    
    
    
    
    
    
    
    '-------------------------------------------------------------------------------------------------------------------------
    Else If (ETAT_SERVICE) = "Stopservice" Then
            return = objService.StopService(WIN_SERVICE1)
    
    
    'Create Shell object
    set objShell = CreateObject("Shell.Application")
    'Verify that the  service is Stop. If it isn't, then stop it.
    
    iF objShell.IsServiceRunning(WIN_SERVICE1) = FALSE Then
    WScript.echo ("tata stop")
    WScript.Sleep 10000
    objShell.ServiceStart (WIN_SERVICE1), TRUE
    WScript.Sleep 10000
    objShell.ServiceStop (WIN_SERVICE1), TRUE
    else If objShell.IsServiceRunning(WIN_SERVICE1) = TRUE Then
    WScript.echo ("tata start")
    WScript.Sleep 10000
    objShell.ServiceStop (WIN_SERVICE1), TRUE
    WScript.Sleep 1000
    end if
    end if
    
    
    
            If Err.Number = 0 Then
                    Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                    Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                    FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab & (message)
                    FtxtBis.Close
                    Set FtxtBis = Nothing
                    Ftxt.Close
                    Set Ftxt = Nothing
    
            Else
                    Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
                    Set Ftxt = FSO.GetFile("D:\production\home\tws\log\SYS_LOG_systeme.log")
                    Set FtxtBis = Ftxt.OpenAsTextStream(8, -2)
                    FtxtBis.writeline (Year(date)) & vbTab & (Month(date)) & vbTab & (Day(date)) & vbTab & (time) & vbTab & (getSystemVar("COMPUTERNAME")) & vbTab & resultat1 & vbTab & resultat2 & vbTab & (PID) & vbTab & (terminal) & vbTab & resultat5 & vbTab & resultat4 & vbTab & return & vbTab & (gravite) & vbTab & resultat3 & vbTab & (getSystemVar("UNISON_JOBNUM")) & vbTab & (valeur) & vbTab & (message)
                    FtxtBis.Close 'Fermeture
                    Set FtxtBis = Nothing
                    Ftxt.Close
                    Set Ftxt = Nothing
            End If
    FSO.Close
    
    '- Ecrire dans l'event Log
    
    Set objShell = Wscript.CreateObject("Wscript.Shell")
    objShell.LogEvent EVENT_SUCCESS, _
    (now) & chr(10) & "Les services" &  chr(1) & (strService) & "sur le serveur" & chr(1) & (getSystemVar ("COMPUTERNAME")) & chr(1) & "ont étés" & chr(1) & "par l'utilisateur" & chr(1) & (getSystemVar("username"))' & chr(1) & (sh.IsServiceRunning("Alerter"))	
    
    WScript.Quit(return)
    
            End If
    End If
    
    WSCript.Sleep intSleep
    Next

    Dans l'attente de vos lumieres, je vous sohaite une bonne journée.

Discussions similaires

  1. Connaître le statut d'un service
    Par titou624 dans le forum Android
    Réponses: 15
    Dernier message: 21/11/2011, 22h13
  2. script recupération du statut d'un service
    Par dousa1 dans le forum Scripts/Batch
    Réponses: 23
    Dernier message: 30/09/2009, 15h13
  3. Probleme d'input/output XML pour Web service Java - AXIS2
    Par 2beornot2be dans le forum Services Web
    Réponses: 1
    Dernier message: 06/08/2009, 11h59
  4. probleme avec generic host process for win32 services
    Par thesorrow dans le forum Windows XP
    Réponses: 2
    Dernier message: 15/03/2007, 10h29
  5. Connaitre le statut d'un service
    Par clementv dans le forum Administration système
    Réponses: 8
    Dernier message: 08/06/2006, 08h47

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