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 test de Service


Sujet :

VBScript

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

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Par défaut Probleme test de Service
    Bonjour a tous,

    Voici mon code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    Dim objWMIService, objItem, objService
    Set args  = Wscript.Arguments
    WIN_SERVICE1 = args(0)
    Set sh = CreateObject("Shell.Application") 
     
    MsgBox sh.IsServiceRunning(WIN_SERVICE1) 
     
    if sh.IsServiceRunning(WIN_SERVICE1)= faux then
     
    	objService.StartService(WIN_SERVICE1)
     
    end if
    Celui ci me permet de checker si le service est démarré Il me renvoie son etat par vrai ou faux.

    Ma condition est que si celui -ci est faux il doit le démarrer mais le probleme c'est qu il me demande des "
    Voir le fichier joint

    Merci de votre aide
    Images attachées Images attachées  

  2. #2
    Membre confirmé
    Inscrit en
    Avril 2003
    Messages
    105
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 105
    Par défaut
    Salut

    Peut être que le service que tu veux démarrer contient un caractère spécial comme l'apostrophe ou les guillements dans son nom !

    Kayser

  3. #3
    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 déjà objService n'est initialisé nulle-part...

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

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Par défaut
    Si si il est initialisé au debut

  5. #5
    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
    Citation Envoyé par lephyrexian
    Si si il est initialisé au debut
    ? ou ( la ligne Dim c'est juste une déclaration..)

  6. #6
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Par défaut
    ben je vois pas ce que tu veux dire alors

  7. #7
    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
    Citation Envoyé par lephyrexian
    ben je vois pas ce que tu veux dire alors
    je ne sais pas d'ou viens ton code ... mais il en manque un morceau .. tu ne peu pas appliquer une procédure sur objet qui n'as pas été initialisé ... ici tu as
    objService = Nothing !

  8. #8
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Par défaut
    c'est une partie du script que j'ai fait. Je n'ai jamais initialisé objService et mon script marche. En faite ce que je veux faire c'est amélioré mon script pour que celui-ci teste le service s'il est demarré ou pas. Et en fonction de son etat si on a demandé de l'arreter et que celui-ci est deja arreter je veux qu il demarre le service pour le stopper.
    Si vous voulez je vous metsle code entier qui lui marche.

    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
     
    ' '  Assignation des variables pour Post message Tivoli ou Log
    ' =============================================================================
     
    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
     
    ' =============================================================================
    '  Paramètre(s) entree :
    '
    '  Sortie : (fichiers, tables, codes erreur, ...)
    ' -----------------------------------------------------------------------------
    '
    '
    ' -----------------------------------------------------------------------------
    ' Action principale
    ' --------------------
     
    '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)
     
    '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)
     
            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
     
    ' -----------------------------------------------------------------------------
    '  Fin du Main {}
    Merci pour votre aide

  9. #9
    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
    pour l'init on n'avais pas vu la ligne :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    For Each objService in colListOfServices

  10. #10
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    79
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 79
    Par défaut
    Et pour ce que je veux faire comment est ce que je dois le faire ou proceder.
    Please aider moi ou mettez moi sur la voie

    Merci

Discussions similaires

  1. probleme avec Analysis Services de sql server 2000
    Par thefaycal dans le forum MS SQL Server
    Réponses: 1
    Dernier message: 13/02/2006, 16h41
  2. Problem Linux>php>services
    Par sebeni dans le forum Linux
    Réponses: 4
    Dernier message: 25/01/2006, 15h05
  3. [probleme] teste de saisie de formulaire
    Par razielmyth dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 04/01/2006, 11h43
  4. probleme test presence d'un fichier(avec fso)
    Par pagez dans le forum Général JavaScript
    Réponses: 7
    Dernier message: 30/08/2005, 15h24

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