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 :

Equivalence Goto en VBS


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  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 Equivalence Goto en VBS
    Bonjour,

    Y a t il une commande equivalente a goto en VBS

    merci

  2. #2
    Membre Expert
    Avatar de pc75
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    3 662
    Détails du profil
    Informations personnelles :
    Âge : 70
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Septembre 2004
    Messages : 3 662
    Par défaut
    Bonjour,

    Il faudrait que tu sois plus précis. Tu veux faire quoi exactement ?

  3. #3
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Le goto est à bannir des codes !!!

  4. #4
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Sinon en VBS, le goto est utilisé pour la gestion des erreurs.

  5. #5
    Expert confirmé
    Avatar de ced600
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Août 2006
    Messages
    3 364
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Par défaut
    Heu...
    pkoi veut tu te servir du goto ?

  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
    Je ne veux pas forcement utiliser le goto mais je veux que dans l ecriture de la log il n 'y ait qu'une seul fois l'ecriture et pas 2 fois.

    Merci

  7. #7
    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
    Voila mon code

    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
    Dim ETAT_SERVICE
    Dim WIN_SERVICE1
     
    Set FSO = CreateObject("Scripting.FileSystemObject")
    On Error Resume Next
     
    Set Ftxt = FSO.CreateTextFile("D:\production\home\tws\log\SYS_LOG_systeme.log", False)
     
    Function getSystemVar(VarName)
        Dim wss, env
        Set wss = CreateObject("WScript.Shell")
        Set env = wss.environment("process")
        getSystemVar = env(VarName)
    End Function
     
    Dim objWMIService, objItem, objService
    Dim colListOfServices, strComputer, intSleep
    strComputer = "."
    intSleep = 5000
     
    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
     
     
     
    If (ETAT_SERVICE) <> "Startservice" and (ETAT_SERVICE) <> "Stopservice" Then
     
    parametre = "Parametre Invalide"
    If Err.Number = 0 Then 'Fichier Log n'existe pas
      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 'Fichier log existe
      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
     
    end if
     
     
    If (ETAT_SERVICE) = "Startservice" Then
      return = objService.StartService(WIN_SERVICE1)
          if Return = 5 then
             Return = 0
          else 
             if Return = 10 then
                Return = 0
             end if
          end if
      Else If (ETAT_SERVICE) = "Stopservice" Then
       return = objService.StopService(WIN_SERVICE1)
          if Return = 5 then
             Return = 0
          else 
             if Return = 10 then
                Return = 0
             end if
          end if
     End If
    End If
     
    WSCript.Sleep intSleep
    Next
     
    If Err.Number = 0 Then 'Fichier Log n'existe pas
      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 &(parametre) & vbTab & (message)
      FtxtBis.Close 
      Set FtxtBis = Nothing
      Ftxt.Close 
      Set Ftxt = Nothing
     
    Else 'Fichier log existe
      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 &(parametre)& vbTab & (message)
      FtxtBis.Close 'Fermeture
      Set FtxtBis = Nothing
      Ftxt.Close
      Set Ftxt = Nothing
    End If
    FSO.Close
    Ce que je veux faire c'est la chose suivante:

    Lorsque je teste mon parametre et que celui ci est pas bon je veux qu il ecrive dans mon fichier "parametre invalide" sinon qu il ecrive les valeurs recuperées.
    Sur ce script j arrive a ecrire ce que je veux maisle soucis est qu il m ecrit les ligne en double lorsque la commande est bonne.
    Voici mon resultat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    2006 11 16 14:03:34	Parametre Invalide The Service 'Alerter'is in state :StopService
    2006 11 16 14:03:49 0 The service 'Alerter' is in state :Startservice
    Normalement j aurais du avoir une ligne d'ecrite.

    Merci de m aider

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

Discussions similaires

  1. Equivalent de ShowModalDialog pour un VBS
    Par papyxy dans le forum VBScript
    Réponses: 6
    Dernier message: 23/11/2012, 15h58
  2. Equivalent "On Cancel GoTo"???
    Par Monfy29 dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 31/03/2010, 10h06
  3. equivalent de goto dans access
    Par Skizo dans le forum Access
    Réponses: 3
    Dernier message: 12/05/2006, 15h22
  4. [VBS] Redirection (équivalent Goto ms-dos)
    Par Edoxituz dans le forum VBScript
    Réponses: 8
    Dernier message: 23/02/2006, 20h14
  5. Equivalent de Left() de VBS en PHP
    Par mioux dans le forum Langage
    Réponses: 2
    Dernier message: 09/12/2005, 15h15

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