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 :

générer un vbs


Sujet :

VBScript

  1. #1
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut générer un vbs
    Bonjour, j'ai un script senser générer un vbs, mais il me mais l'erreur ")" attendu, ne faut il pas ajouter un caractére d'échepement comme en batch ?
    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
     
    Const ForReading = 1, ForWriting = 2 
      Set FichierTXT = WScript.CreateObject("WScript.Shell") 
       Dim fso, f 
       Set fso = CreateObject("Scripting.FileSystemObject")
       f.writeline("vrTestDisuKook = "Z:\KooKaTix_Interface" ' Cette variable ser à la condition IF pour tester si je sui bien sur mon PC en testant mon répertoire de mon diosque kookatix")
       f.writeline("Set objFSO = CreateObject("Scripting.FileSystemObject")")
       f.writeline("        If objFSO.FolderExists(vrTestDisuKook) Then")
       f.writeline("Dim prec")
       f.writeline("ForReading=1")
       f.writeline("Const SW_HIDE=0")
       f.writeline("Const SW_SHOWNORMAL=1 ")
       f.writeline("Dim shell, fldrs, fso, ts")
       f.writeline("Set shell = WScript.CreateObject("WScript.Shell")")
       f.writeline("Set fso = WScript.CreateObject("Scripting.FileSystemObject")")
       f.writeline("FileResult="" & Left(WScript.ScriptFullName, 2) & "\Ma clé\Mes Sites Favoris .html"")
       f.writeline("Set ts=fso.CreateTextFile(FileResult, true,true)")
       f.writeline("' Récupération du chemin du dossier "Favoris"")
       f.writeline("Set fldrs = Shell.SpecialFolders")
       f.writeline("fav=fldrs("Favorites")")
       f.writeline("ColorBack="""#FFFFD8"""")
       f.writeline("ts.Writeline "<HTML><head><title>" & "Favoris" & "</title>" ")
       f.writeline("ts.Writeline "<html><head><title>" & Titre & "</title>" ")
       f.writeline("ts.Writeline "<STYLE TYPE=""text/css"">"")
       f.writeline("ts.Writeline "body {" ")
       f.writeline("ts.Writeline "	font-family: Verdana;" ")
       f.writeline("ts.Writeline "	font-size: 8 pt }" ")
       f.writeline("ts.Writeline "	h1, h2, h3, h4, h5  { font-family: Verdana }" ")
       f.writeline("ts.Writeline "</STYLE></head><body bgcolor=" & ColorBack &">"")
       f.writeline("ts.WriteLine "<h3>Dossier des favoris : " & fav & "</h3>"")
       f.writeline("indfav=InstrRev(fav,"\")+1")
       f.writeline("prec=""")
       f.writeline("ts.writeline "<ul>"")
       f.writeline("call explorefolder(fav,"Favoris")")
       f.writeline("ts.WriteLine "</ul></body></html>"")
       f.writeline("ts.close")
       f.writeline("	commande=chr(34) & FileResult & chr(34)")
       f.writeline("shell.Run commande, SW_SHOWNORMAL, false")
       f.writeline("wscript.quit")
       f.writeline("'----------------------------------------------------")
       f.writeline("' Sous-programme récursif d'exploration des dossiers")
       f.writeline("sub	explorefolder(namefolder,curfolder)")
       f.writeline("dim f,collfolders,collfiles")
       f.writeline("Set f = fso.GetFolder(namefolder)")
       f.writeline("' Collection des fichiers et sous-dossiers du dossier courant")
       f.writeline("Set collfolders=  f.SubFolders ")
       f.writeline("Set collfiles  =  f.Files")
       f.writeline("subname=mid(namefolder,indfav)")
       f.writeline("ts.writeline "<li><b>" & curfolder & "</b><ul>"")
       f.writeline("' Exploration des fichiers contenus")
       f.writeline("nf=0")
       f.writeline("For each fic in collfiles")
       f.writeline("	ext=LCase(right(fic.Name, 4))")
       f.writeline("' On ne retient que les fichiers *.url")
       f.writeline("	If ext=".url" Then")
       f.writeline("		nf=nf+1")
       f.writeline("		titre=left(fic.Name,Len(fic.Name)-4)")
       f.writeline("		set curf=fic.OpenAsTextStream(ForReading, TristateUseDefault)")
       f.writeline("' On lit le fichier et recherche l'item "URL=..."")
       f.writeline("		Do While (curf.AtEndOfStream <>true)")
       f.writeline("			ligne=curf.readline")
       f.writeline("			If lcase(left(ligne,4))="url=" Then")
       f.writeline("				URL=right(ligne,len(ligne)-4)")
       f.writeline("				lenURL=len(URL)")
       f.writeline("				URL2=""")
       f.writeline("				i=1")
       f.writeline("				lmax=80")
       f.writeline("				Do while i<=lenURL")
       f.writeline("					If URL2<>"" Then URL2=URL2 & VBCRLF")
       f.writeline("					URL2=URL2 & "     " & mid(URL,i,lmax)")
       f.writeline("					i=i+lmax")
       f.writeline("					Loop")
       f.writeline("				exit Do")
       f.writeline("				End If")
       f.writeline("			Loop")
       f.writeline("		curf.close")
       f.writeline("		ts.writeline "<li><a href=" & chr(34) & URL2 & chr(34) & ">" & titre & "</a></li>"")
       f.writeline("	   End If")
       f.writeline("	 Next")
       f.writeline("' Exploration récursive des sous-dossiers")
       f.writeline("For each folder in collfolders ")
       f.writeline("	newfolder=namefolder & "\" & folder.Name")
       f.writeline("	call explorefolder(newfolder,folder.Name)")
       f.writeline("	Next")
       f.writeline("ts.writeline "</ul></li>"")
       f.writeline("end sub")
       f.writeline("'--------------------------------------------------------------------")
       f.writeline("' Fonction de récupération du répertoire courant")
       f.writeline("Function GetPath()")
       f.writeline("Dim path")
       f.writeline("path = WScript.ScriptFullName")
       f.writeline("GetPath = Left(path, InStrRev(path, "\"))")
       f.writeline("End Function")
       f.writeline("        Else")
       f.writeline("           Wscript.Echo vrMessgDisquKookNotExist")
       f.writeline("        End If")
    Donc quel est la caractére d'échapement ? (que je puisse tester)

  2. #2
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    117
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 117
    Points : 149
    Points
    149
    Par défaut
    Salut,

    Il me semble que les concaténations de chaîne ne sont pas faite correctement.

    Ex :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    f.writeline("vrTestDisuKook = "Z:\KooKaTix_Interface"
    devrait être
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    f.writeline("vrTestDisuKook = """ & "Z:\KooKaTix_Interface" & """)

  3. #3
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    je ne pensse pas que sa vienne de la, le code que j'essai de générer fonctionne trés bien, je croi qu'il me faut le caractére d'échapement ?

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Janvier 2008
    Messages
    117
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2008
    Messages : 117
    Points : 149
    Points
    149
    Par défaut
    bien souvent le caractère d'échappement est "\" mais bon c'est bien souvent

  5. #5
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    je croi que c'est pas ca en vbs

  6. #6
    Expert éminent sénior


    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
    Points : 20 038
    Points
    20 038
    Par défaut
    en vbs ... pour "échapper" des " tu les doubles... donc partout où tu veux qu'il y ait un " dans ton fichier générer , tu en met 2 ..!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       f.writeline("Set objFSO = CreateObject(""Scripting.FileSystemObject"")")
    où tu utilise Chr(34) :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
       f.writeline("Set objFSO = CreateObject(" & Chr(34) & "Scripting.FileSystemObject" & Chr(34) & ")")

  7. #7
    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 : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par trollinou Voir le message
    Salut,

    Il me semble que les concaténations de chaîne ne sont pas faite correctement.

    Ex :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    f.writeline("vrTestDisuKook = "Z:\KooKaTix_Interface"
    devrait être
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    f.writeline("vrTestDisuKook = """ & "Z:\KooKaTix_Interface" & """)
    Je confirlme que le caractère d'échapement est ".
    Et donc trollinou a raison tes concaténation sont mauvaise.
    La méthode qu'il te propose est bonne, et tu devrait faire ainsi car c'est plus lisible. Autrement tu peux faire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    f.writeline("vrTestDisuKook = ""Z:\KooKaTix_Interface""")
    Edit : Trop lent
    Heu ... non l'inverse plus rapide
    Me faut un
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  8. #8
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    merci beaucoup bbil

  9. #9
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Donc voici mon script maitenant:
    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
    set WshShell = WScript.CreateObject("WScript.Shell")               
    Set FSO = CreateObject("Scripting.FileSystemObject")
     
    Const ForReading = 1, ForWriting = 2 
      Set FichierTXT = WScript.CreateObject("WScript.Shell") 
       Dim fso, f 
       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set f = fso.OpenTextFile("fav.vbs", ForWriting,true) 
       f.writeline("vrTestDisuKook = ""Z:\KooKaTix_Interface"" ' Cette variable ser à la condition IF pour tester si je sui bien sur mon PC en testant mon répertoire de mon diosque kookatix")
       f.writeline("Set objFSO = CreateObject(""Scripting.FileSystemObject"")")
       f.writeline("        If objFSO.FolderExists(vrTestDisuKook) Then")
       f.writeline("Dim prec")
       f.writeline("ForReading=1")
       f.writeline("Const SW_HIDE=0")
       f.writeline("Const SW_SHOWNORMAL=1 ")
       f.writeline("Dim shell, fldrs, fso, ts")
       f.writeline("Set shell = WScript.CreateObject(""WScript.Shell"")")
       f.writeline("Set fso = WScript.CreateObject(""Scripting.FileSystemObject"")")
       f.writeline("FileResult="""" & Left(WScript.ScriptFullName, 2) & ""\Ma clé\Mes Sites Favoris .html""")
       f.writeline("Set ts=fso.CreateTextFile(FileResult, true,true)")
       f.writeline("' Récupération du chemin du dossier ""Favoris""")
       f.writeline("Set fldrs = Shell.SpecialFolders")
       f.writeline("fav=fldrs(""Favorites"")")
       f.writeline("ColorBack=""""""#FFFFD8""""""")
       f.writeline("ts.Writeline ""<HTML><head><title>"" & ""Favoris"" & ""</title>"" ")
       f.writeline("ts.Writeline ""<html><head><title>"" & Titre & ""</title>"" ")
       f.writeline("ts.Writeline ""<STYLE TYPE=""""text/css"""">""")
       f.writeline("ts.Writeline ""body {"" ")
       f.writeline("ts.Writeline ""	font-family: Verdana;"" ")
       f.writeline("ts.Writeline ""	font-size: 8 pt }"" ")
       f.writeline("ts.Writeline ""	h1, h2, h3, h4, h5  { font-family: Verdana }"" ")
       f.writeline("ts.Writeline ""</STYLE></head><body bgcolor="" & ColorBack &"">""")
       f.writeline("ts.WriteLine ""<h3>Dossier des favoris : "" & fav & ""</h3>""")
       f.writeline("indfav=InstrRev(fav,""\"")+1")
       f.writeline("prec=""""")
       f.writeline("ts.writeline ""<ul>""")
       f.writeline("call explorefolder(fav,""Favoris"")")
       f.writeline("ts.WriteLine ""</ul></body></html>""")
       f.writeline("ts.close")
       f.writeline("	commande=chr(34) & FileResult & chr(34)")
       f.writeline("shell.Run commande, SW_SHOWNORMAL, false")
       f.writeline("wscript.quit")
       f.writeline("'----------------------------------------------------")
       f.writeline("' Sous-programme récursif d'exploration des dossiers")
       f.writeline("sub	explorefolder(namefolder,curfolder)")
       f.writeline("dim f,collfolders,collfiles")
       f.writeline("Set f = fso.GetFolder(namefolder)")
       f.writeline("' Collection des fichiers et sous-dossiers du dossier courant")
       f.writeline("Set collfolders=  f.SubFolders ")
       f.writeline("Set collfiles  =  f.Files")
       f.writeline("subname=mid(namefolder,indfav)")
       f.writeline("ts.writeline ""<li><b>"" & curfolder & ""</b><ul>""")
       f.writeline("' Exploration des fichiers contenus")
       f.writeline("nf=0")
       f.writeline("For each fic in collfiles")
       f.writeline("	ext=LCase(right(fic.Name, 4))")
       f.writeline("' On ne retient que les fichiers *.url")
       f.writeline("	If ext="".url"" Then")
       f.writeline("		nf=nf+1")
       f.writeline("		titre=left(fic.Name,Len(fic.Name)-4)")
       f.writeline("		set curf=fic.OpenAsTextStream(ForReading, TristateUseDefault)")
       f.writeline("' On lit le fichier et recherche l'item ""URL=...""")
       f.writeline("		Do While (curf.AtEndOfStream <>true)")
       f.writeline("			ligne=curf.readline")
       f.writeline("			If lcase(left(ligne,4))=""url="" Then")
       f.writeline("				URL=right(ligne,len(ligne)-4)")
       f.writeline("				lenURL=len(URL)")
       f.writeline("				URL2=""""")
       f.writeline("				i=1")
       f.writeline("				lmax=80")
       f.writeline("				Do while i<=lenURL")
       f.writeline("					If URL2<>"""" Then URL2=URL2 & VBCRLF")
       f.writeline("					URL2=URL2 & ""     "" & mid(URL,i,lmax)")
       f.writeline("					i=i+lmax")
       f.writeline("					Loop")
       f.writeline("				exit Do")
       f.writeline("				End If")
       f.writeline("			Loop")
       f.writeline("		curf.close")
       f.writeline("		ts.writeline ""<li><a href="" & chr(34) & URL2 & chr(34) & "">"" & titre & ""</a></li>""")
       f.writeline("	   End If")
       f.writeline("	 Next")
       f.writeline("' Exploration récursive des sous-dossiers")
       f.writeline("For each folder in collfolders ")
       f.writeline("	newfolder=namefolder & ""\"" & folder.Name")
       f.writeline("	call explorefolder(newfolder,folder.Name)")
       f.writeline("	Next")
       f.writeline("ts.writeline ""</ul></li>""")
       f.writeline("end sub")
       f.writeline("'--------------------------------------------------------------------")
       f.writeline("' Fonction de récupération du répertoire courant")
       f.writeline("Function GetPath()")
       f.writeline("Dim path")
       f.writeline("path = WScript.ScriptFullName")
       f.writeline("GetPath = Left(path, InStrRev(path, ""\""))")
       f.writeline("End Function")
       f.writeline("        Else")
       f.writeline("           Wscript.Echo vrMessgDisquKookNotExist")
       f.writeline("        End If")
    WshShell.Run "wscript fav.vbs"
    Set fsoFile = fso.getFile("fav.vbs")
     fsoFile.delete
    Mais la ligne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    WshShell.Run "wscript fav.vbs"
    Me renvoi l'erreur:


    Saurais tu me dire ce qui ne va pas ?

  10. #10
    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 : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Tu ne fermes pas ton fichier après avoir écrit dedans.
    Donc il reste ouvert.
    un f.close après ton dernier f.writeline
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  11. #11
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    merci

    J'ai donc ajouter f.close mais la le fichier n'est plus générer

    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
    set WshShell = WScript.CreateObject("WScript.Shell")               
    Set FSO = CreateObject("Scripting.FileSystemObject")
     
    Const ForReading = 1, ForWriting = 2 
      Set FichierTXT = WScript.CreateObject("WScript.Shell") 
       Dim fso, f 
       Set fso = CreateObject("Scripting.FileSystemObject") 
       Set f = fso.OpenTextFile("fav.vbs", ForWriting,true) 
       f.writeline("vrTestDisuKook = ""Z:\KooKaTix_Interface"" ' Cette variable ser à la condition IF pour tester si je sui bien sur mon PC en testant mon répertoire de mon diosque kookatix")
       f.writeline("Set objFSO = CreateObject(""Scripting.FileSystemObject"")")
       f.writeline("        If objFSO.FolderExists(vrTestDisuKook) Then")
       f.writeline("Dim prec")
       f.writeline("ForReading=1")
       f.writeline("Const SW_HIDE=0")
       f.writeline("Const SW_SHOWNORMAL=1 ")
       f.writeline("Dim shell, fldrs, fso, ts")
       f.writeline("Set shell = WScript.CreateObject(""WScript.Shell"")")
       f.writeline("Set fso = WScript.CreateObject(""Scripting.FileSystemObject"")")
       f.writeline("FileResult="""" & Left(WScript.ScriptFullName, 2) & ""\Ma clé\Mes Sites Favoris .html""")
       f.writeline("Set ts=fso.CreateTextFile(FileResult, true,true)")
       f.writeline("' Récupération du chemin du dossier ""Favoris""")
       f.writeline("Set fldrs = Shell.SpecialFolders")
       f.writeline("fav=fldrs(""Favorites"")")
       f.writeline("ColorBack=""""""#FFFFD8""""""")
       f.writeline("ts.Writeline ""<HTML><head><title>"" & ""Favoris"" & ""</title>"" ")
       f.writeline("ts.Writeline ""<html><head><title>"" & Titre & ""</title>"" ")
       f.writeline("ts.Writeline ""<STYLE TYPE=""""text/css"""">""")
       f.writeline("ts.Writeline ""body {"" ")
       f.writeline("ts.Writeline ""	font-family: Verdana;"" ")
       f.writeline("ts.Writeline ""	font-size: 8 pt }"" ")
       f.writeline("ts.Writeline ""	h1, h2, h3, h4, h5  { font-family: Verdana }"" ")
       f.writeline("ts.Writeline ""</STYLE></head><body bgcolor="" & ColorBack &"">""")
       f.writeline("ts.WriteLine ""<h3>Dossier des favoris : "" & fav & ""</h3>""")
       f.writeline("indfav=InstrRev(fav,""\"")+1")
       f.writeline("prec=""""")
       f.writeline("ts.writeline ""<ul>""")
       f.writeline("call explorefolder(fav,""Favoris"")")
       f.writeline("ts.WriteLine ""</ul></body></html>""")
       f.writeline("ts.close")
       f.writeline("	commande=chr(34) & FileResult & chr(34)")
       f.writeline("shell.Run commande, SW_SHOWNORMAL, false")
       f.writeline("wscript.quit")
       f.writeline("'----------------------------------------------------")
       f.writeline("' Sous-programme récursif d'exploration des dossiers")
       f.writeline("sub	explorefolder(namefolder,curfolder)")
       f.writeline("dim f,collfolders,collfiles")
       f.writeline("Set f = fso.GetFolder(namefolder)")
       f.writeline("' Collection des fichiers et sous-dossiers du dossier courant")
       f.writeline("Set collfolders=  f.SubFolders ")
       f.writeline("Set collfiles  =  f.Files")
       f.writeline("subname=mid(namefolder,indfav)")
       f.writeline("ts.writeline ""<li><b>"" & curfolder & ""</b><ul>""")
       f.writeline("' Exploration des fichiers contenus")
       f.writeline("nf=0")
       f.writeline("For each fic in collfiles")
       f.writeline("	ext=LCase(right(fic.Name, 4))")
       f.writeline("' On ne retient que les fichiers *.url")
       f.writeline("	If ext="".url"" Then")
       f.writeline("		nf=nf+1")
       f.writeline("		titre=left(fic.Name,Len(fic.Name)-4)")
       f.writeline("		set curf=fic.OpenAsTextStream(ForReading, TristateUseDefault)")
       f.writeline("' On lit le fichier et recherche l'item ""URL=...""")
       f.writeline("		Do While (curf.AtEndOfStream <>true)")
       f.writeline("			ligne=curf.readline")
       f.writeline("			If lcase(left(ligne,4))=""url="" Then")
       f.writeline("				URL=right(ligne,len(ligne)-4)")
       f.writeline("				lenURL=len(URL)")
       f.writeline("				URL2=""""")
       f.writeline("				i=1")
       f.writeline("				lmax=80")
       f.writeline("				Do while i<=lenURL")
       f.writeline("					If URL2<>"""" Then URL2=URL2 & VBCRLF")
       f.writeline("					URL2=URL2 & ""     "" & mid(URL,i,lmax)")
       f.writeline("					i=i+lmax")
       f.writeline("					Loop")
       f.writeline("				exit Do")
       f.writeline("				End If")
       f.writeline("			Loop")
       f.writeline("		curf.close")
       f.writeline("		ts.writeline ""<li><a href="" & chr(34) & URL2 & chr(34) & "">"" & titre & ""</a></li>""")
       f.writeline("	   End If")
       f.writeline("	 Next")
       f.writeline("' Exploration récursive des sous-dossiers")
       f.writeline("For each folder in collfolders ")
       f.writeline("	newfolder=namefolder & ""\"" & folder.Name")
       f.writeline("	call explorefolder(newfolder,folder.Name)")
       f.writeline("	Next")
       f.writeline("ts.writeline ""</ul></li>""")
       f.writeline("end sub")
       f.writeline("'--------------------------------------------------------------------")
       f.writeline("' Fonction de récupération du répertoire courant")
       f.writeline("Function GetPath()")
       f.writeline("Dim path")
       f.writeline("path = WScript.ScriptFullName")
       f.writeline("GetPath = Left(path, InStrRev(path, ""\""))")
       f.writeline("End Function")
       f.writeline("        Else")
       f.writeline("           Wscript.Echo vrMessgDisquKookNotExist")
       f.writeline("        End If")
      f.close
    WshShell.Run "wscript fav.vbs"
    Set fsoFile = fso.getFile("fav.vbs")
     fsoFile.delete

  12. #12
    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 : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    bah en même temps avec ton fso.delete tu la supprimes
    delete = supprimer en français.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  13. #13
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Ah oui, ok, j'aurai pennser que ca aurai supprimer le fichier aprés sont éxécution

  14. #14
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    J'ai don mis ce script dans un autre script, un menu, et en tête du script mére j'ai ajouter ceci pour qu'il supprime le fichier fav.vbs:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    If objFSO.FolderExists("fav.vbs") Then
            Set fsoFile = fso.getFile("fav.vbs")
             fsoFile.delete
    Else
    End If
    Mais ca ne marche pas, ais-je omi quelque chose ?

  15. #15
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    comme un con j'ai mi folder au lieu de file:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    If objFSO.FileExists("fav.vbs") Then
            Set fsoFile = fso.getFile("fav.vbs")
             fsoFile.delete
    Else
    End If

  16. #16
    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 : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    La avec ce code tu testes si le fichier existe, et s'il existe tu le supprimes.
    Donc oui cela ne fera pas ce que tu veux.

    Si tu veux attendre la fin de l'exécution il faut que testes si le processus lancé et toujours présent dans la liste des processus de windows, et lorsque ce n'est plus le cas, tu peux supprimer le fichier.

    Je t'ai fait un petit script :
    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
    RunAndWaitUntilFinish
     
    'Lance un processus notepad.exe et attend la fin de celui-ci avant d'afficher une msgbox.
    'Remplace la msgbox par la suppression du fichioer et notepad.exe par le chemin de ton script
    sub RunAndWaitUntilFinish()
    	Dim PID
    	Dim NotRun
     
    	Run = true
    	PID = RunProcess ("notepad.exe")
     
    	Do while Run = true
    		Run = false
    		strComputer = "."
    		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    		Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    		Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process")
    		for each process in colProcessList
    			If process.ProcessID = PID Then
    				Run = true
    			End If
    		Next
    		Wscript.sleep 500
    	Loop
     
    	msgbox "Fini"
     
    	'Pour tester les deux premières fonctions :
    	msgbox GetProcessNameByPID(GetProcessIDByName("IEXPLORE.exe"))
     
    end sub
     
    'Obtenir le PID du process par le nom
    Function GetProcessIDByName (name)
    	Dim intProcessID
     
    	'Obtention de la liste des processus.
    	strComputer = "."
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    	Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    	Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process")
     
    	'On parcours la liste et si le nom d'un processus et égal au nom donné en paramètre, on récupère le PID.
    	for each process in colProcessList
    		If Ucase(Trim(process.Name)) = Ucase(Trim(name)) Then
    			intProcessID = process.ProcessID
    		End If
    	Next
     
    	If errReturn Then
    		err.Number = errReturn
    		err.Description = "Erreur lors de la création du processus"
    	End If
    	GetProcessIDByName = intProcessID
    End Function
     
     
     
     
    'Obtenir le nom du process par le PID
    Function GetProcessNameByPID (ID)
    	Dim ProcessName
     
    	'Obtention de la liste des processus.
    	strComputer = "."
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    	Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    	Set colProcessList = objWMIService.ExecQuery ("Select * from Win32_Process")
     
    	'On parcours la liste et si le PID d'un processus et égal au PID donné en paramètre, on récupère son nom.
    	for each process in colProcessList
    		If process.ProcessID = ID Then
    			ProcessName = Ucase(Trim(process.Name))
    		End If
    	Next
     
    	If errReturn Then
    		err.Number = errReturn
    		err.Description = "Erreur lors de la création du processus"
    	End If
    	GetProcessNameByPID = ProcessName
    End Function
     
     
     
     
    'Lancer un process et renvoyer son ID
    'Path représente le chemin du fichier à exécuter : dans ton cas le fichier VBS
    Function RunProcess (path)
    	Dim intProcessID
     
    	strComputer = "."
    	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    	Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
     
    	errReturn = objProcess.Create(path, null, null, intProcessID)
     
    	If errReturn Then
    		err.Number = errReturn
    		err.Description = "Erreur lors de la création du processus"
    	End If
    	RunProcess = intProcessID
    End Function
    Edit : Pas vu le coup du folder.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

  17. #17
    Débutant  
    Avatar de koKoTis
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 438
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 438
    Points : 2 415
    Points
    2 415
    Par défaut
    Merci pour ce script

    Mais il est un peut trop long pour que je l'intégre dans mon script qui est lui même déja asser long, je vai laisser le if en tête du script ca suffira.


    Moi ton script je vai quand même le garder

  18. #18
    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 : 42
    Localisation : France

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Août 2006
    Messages : 3 364
    Points : 4 061
    Points
    4 061
    Par défaut
    Citation Envoyé par koKoTis Voir le message
    Merci pour ce script

    Mais il est un peut trop long pour que je l'intégre dans mon script qui est lui même déja asser long, je vai laisser le if en tête du script ca suffira.


    Moi ton script je vai quand même le garder
    lol moi aussi.
    Pourquoi faire compliqué lorsque l'on peut faire encore plus compliqué.

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

Discussions similaires

  1. Générer du code vbs dans une prog vbs
    Par zz99 dans le forum VBScript
    Réponses: 3
    Dernier message: 20/05/2010, 18h36
  2. Réponses: 1
    Dernier message: 12/01/2007, 08h36
  3. Générer un nombre aléatoire entre 0 et 1 (INCLUS !!!)
    Par haypo dans le forum Algorithmes et structures de données
    Réponses: 3
    Dernier message: 22/08/2002, 16h30
  4. [CR][VB] comment générer un état ?
    Par ndi dans le forum SDK
    Réponses: 3
    Dernier message: 22/08/2002, 13h13
  5. Réponses: 5
    Dernier message: 08/07/2002, 16h22

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