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 :

Download / Execute / Delete Problème


Sujet :

VBScript

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2011
    Messages : 5
    Par défaut Download / Execute / Delete Problème
    Je vous explique mon fichier .vbs télécharge puis enregistre le fichier où se trouve le fichier .vbs et l'exécute mais le problème, je voudrais aussi supprimer le fichier télécharger après avoir été exécuté c'est à dire à la fin du script mais je ne sais pas comment faire pour supprimer un fichier se trouvant dans le même repertoire que le fichier .vbs et si possible après avoir supprimer le fichier téléchargé faire une auto-destruction du fichier .vbs

    Cordialement,

  2. #2
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut
    pouvez vous faire un copier coller de votre code source en le mettant entre

  3. #3
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    Voila tester ce Vbscript que j'ai fait en répondant à une personne dans un forum anglais et je l'ai modifié pour ton besoin
    le Script Original càd Download et exécution seulement sans AutoSupprim Download Image with Vbscript
    et voila le code modifié:
    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
    Dim strFileURL,strHDLocation,Title
    Title = "Download Image with Vbscript + AutoSupprim © Hackoo © 2011"
    Set objFSO = Createobject("Scripting.FileSystemObject")
    PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
    MsgBox PathScript,64,"Chemin du Script" 
    ' ---------------------------------The parameters to be modified to download the Image---------------------------------
        strFileURL = "http://www.google.com/intl/en_com/images/srpr/logo3w.png" ' URL of the image to be downloaded
        strHDLocation = PathScript & "\LogoGoogle.png" 'Name and location of the downloaded Image and you can of course change its name
    ' ---------------------------------The parameters to be modified to download the Image---------------------------------
    ' Get the file
        Set Ws = CreateObject("WScript.Shell")
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        objXMLHTTP.open "GET", strFileURL, false
        objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
    End If
    Set objXMLHTTP = Nothing 
     
    Function Explorer(File)
        Set ws=CreateObject("wscript.shell")
    	ws.Run "explorer " & File
       'ws.Run "explorer /n,/e,/select," & File
    end Function
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
     
    Question = MsgBox ("The File "& qq(strHDLocation) &" is Downloaded Successfully ! " & Vbcr & "Do you want open its location now ?",VBYesNO+VbQuestion,Title)
     If Question = VbYes then
        Call Explorer (strHDLocation)
     End if
     
     wscript.sleep 10000
     
    Question2 = MsgBox ("The File "& qq(strHDLocation) &" must be deleted ! " & Vbcr & "Do you want to delete it now ?",VBYesNO+VbQuestion,Title)
     If Question2 = VbYes then
        If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
     End if 
     
     wscript.sleep 10000
     
     Question3 = MsgBox ("The File "& qq(WScript.ScriptFullName) &" must be deleted ! " & Vbcr & "Do you want to delete it now ?",VBYesNO+VbQuestion,Title)
     If Question3 = VbYes then
      Call  AutoSupprim
     End if 
     
    Sub AutoSupprim
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    objFSO.DeleteFile WScript.ScriptFullName
    Set objFSO = Nothing
    end sub
    Bonne Programmation

  4. #4
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    Voila aussi un autre exemple de code montrant comment Télécharger un Jeu Flash avec exécution par Vbscript + AutoSupprim
    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
    Dim strFileURL,strHDLocation,Title
    Title = "Télécharger un Jeu Flash avec exécution par Vbscript + AutoSupprim © Hackoo © 2011"
    Set objFSO = Createobject("Scripting.FileSystemObject")
    PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
    MsgBox PathScript,64,"Chemin du Script" 
    ' ---------------------------------Les paramètres à modifier pour télécharger le jeu---------------------------------
        strFileURL = "http://www.jeuxclic.com/jeux/game-1270029047.swf"
        strHDLocation = PathScript & "\Coast Bike.swf"
    ' ---------------------------------Les paramètres à modifier pour télécharger le jeu---------------------------------
    ' Récupérer le fichier
        Set Ws = CreateObject("WScript.Shell")
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        objXMLHTTP.open "GET", strFileURL, false
        objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
    End If
    Set objXMLHTTP = Nothing 
     
    Function Explorer()
    'Autoriser le contenu actif à s'exécuter dans les fichiers de la zone Ordinateur local
     LockDown="HKLM\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_LOCALMACHINE_LOCKDOWN\"
     Keysec1=LockDown & "iexplore.exe"
     itemtype = "REG_DWORD"
     WS.RegWrite Keysec1,0,itemtype 
    Ws.Run "%comspec% /c Start iexplore " & strHDLocation, 0, 1 
    wscript.sleep 5000
    WS.SendKeys "{F11}" 'pour mettre internet explorer en plein écran
    Set WS = Nothing
    end Function
     
    Function qq(strIn)
        qq = Chr(34) & strIn & Chr(34)
    End Function
     
    Question = MsgBox ("The File "& qq(strHDLocation) &" is Downloaded Successfully ! " & Vbcr & "Do you want open its location now ?",VBYesNO+VbQuestion,Title)
     If Question = VbYes then
        Call Explorer()
     End if
     
     wscript.sleep 10000
     
    Question2 = MsgBox ("The File "& qq(strHDLocation) &" must be deleted ! " & Vbcr & "Do you want to delete it now ?",VBYesNO+VbQuestion,Title)
     If Question2 = VbYes then
        If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
     End if 
     
     wscript.sleep 10000
     
     Question3 = MsgBox ("The File "& qq(WScript.ScriptFullName) &" must be deleted ! " & Vbcr & "Do you want to delete it now ?",VBYesNO+VbQuestion,Title)
     If Question3 = VbYes then
      Call  AutoSupprim
     End if 
     
    Sub AutoSupprim
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    objFSO.DeleteFile WScript.ScriptFullName
    Set objFSO = Nothing
    end sub

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2011
    Messages : 5
    Par défaut
    Désolé du temps que j'ai pris pour répondre, 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
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    Dim strFileURL,strHDLocation
    ' Tes paramètres
        strFileURL = "Lien du fichier à Télécharger"
        strHDLocation = "Nom avec lequel l'enregistré"
    ' Récupérer le fichier
        Set Ws = CreateObject("WScript.Shell")
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        objXMLHTTP.open "GET", strFileURL, false
        objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    Set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    Set objFSO = Nothing
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
    End If
    Set objXMLHTTP = Nothing 
    Ws.Run strHDLocation
    Set WS = Nothing
    Tu pourrais ajouter la suppression automatique du fichier sans pop-up de demande. Merci

  6. #6
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut

    et surtout n'oublies pas de voter et de fermer cette discussion si elle est résolue en cliquant sur le bouton en bas

    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
    Dim strFileURL,strHDLocation
    ' Tes paramètres
    Set objFSO = Createobject("Scripting.FileSystemObject")
        PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
        strFileURL = "http://www.google.com/intl/en_com/images/srpr/logo3w.png" '"Lien du fichier à Télécharger"
        strHDLocation = PathScript & "\LogoGoogle.png" 'Nom avec lequel l'enregistré
    ' Récupérer le fichier
        Set Ws = CreateObject("WScript.Shell")
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        objXMLHTTP.open "GET", strFileURL, false
        objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    Set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
    End If
    Set objXMLHTTP = Nothing 
    Ws.Run strHDLocation
    wscript.sleep 5000
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation 'Effacer le fichier téléchargé
    Set WS = Nothing
    Set objFSO = Nothing
    wscript.sleep 5000
    Call AutoSupprim() ' Auto-Effacement du Vbscript 
    Sub AutoSupprim()
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    objFSO.DeleteFile WScript.ScriptFullName
    Set objFSO = Nothing
    end sub

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2011
    Messages : 5
    Par défaut
    Erreur à la ligne 26 avec ce 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
    Dim strFileURL,strHDLocation
    ' Tes paramètres
    Set objFSO = Createobject("Scripting.FileSystemObject")
        PathScript = objFSO.GetParentFolderName(wscript.ScriptFullName) 'Chemin ou se localise le Vbscript
        strFileURL = "http://dl.dropbox.com/u/123/jeu.exe" '"Lien du fichier à Télécharger"
        strHDLocation = PathScript & "\Jeu.exe" 'Nom avec lequel l'enregistré
    ' Récupérer le fichier
        Set Ws = CreateObject("WScript.Shell")
        Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
        objXMLHTTP.open "GET", strFileURL, false
        objXMLHTTP.send()
    If objXMLHTTP.Status = 200 Then
    Set objADOStream = CreateObject("ADODB.Stream")
    objADOStream.Open
    objADOStream.Type = 1 'adTypeBinary
    objADOStream.Write objXMLHTTP.ResponseBody
    objADOStream.Position = 0    'Set the stream position to the start
    Set objFSO = Createobject("Scripting.FileSystemObject")
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation
    objADOStream.SaveToFile strHDLocation
    objADOStream.Close
    Set objADOStream = Nothing
    End If
    Set objXMLHTTP = Nothing 
    wscript.sleep 5000
    Ws.Run strHDLocation
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation 'Effacer le fichier téléchargé
    Set WS = Nothing
    Set objFSO = Nothing
    wscript.sleep 5000
    Call AutoSupprim() ' Auto-Effacement du Vbscript 
    Sub AutoSupprim()
    Set objFSO = CreateObject( "Scripting.FileSystemObject" )
    objFSO.DeleteFile WScript.ScriptFullName
    Set objFSO = Nothing
    end sub
    MsgBox "Merci d'avoir joué!" , vbOk + vbCritical, "Chicken Run"

  8. #8
    Expert confirmé
    Avatar de ProgElecT
    Homme Profil pro
    Retraité
    Inscrit en
    Décembre 2004
    Messages
    6 130
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Retraité
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Décembre 2004
    Messages : 6 130
    Par défaut
    Salut

    Des fois la simple inversion de ligne de commande a des conséquences
    Code d'hackoofr
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Ws.Run strHDLocation
    wscript.sleep 5000
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation 'Effacer le fichier téléchargé
    le tien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    wscript.sleep 5000
    Ws.Run strHDLocation
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation 'Effacer le fichier téléchargé
    en fait, tu effaces le programme que tu viens de lancer avant qu'il est été commencer d'être chargé par la commande Run
    :whistle:pourquoi pas, pour remercier, un :plusser: pour celui/ceux qui vous ont dépannés.
    saut de ligne
    OOOOOOOOO👉 → → Ma page perso sur DVP ← ← 👈

  9. #9
    Expert confirmé
    Avatar de hackoofr
    Homme Profil pro
    Enseignant
    Inscrit en
    Juin 2009
    Messages
    3 844
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Juin 2009
    Messages : 3 844
    Par défaut
    Citation Envoyé par HelpMyBrain Voir le message
    Erreur à la ligne 26 avec ce code:

    il faut vérifier bien si votre fichier existe ou pas dans cette URL:
    essais de mettre ce lien directement dans la barre d'adresse de votre navigateur et vous recever automatiquement Error (404) FILE NOT FOUND
    essais de l’héberger dans un autre serveur qui sera le plus souvent disponible

  10. #10
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2011
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2011
    Messages : 5
    Par défaut
    Le lien marche bien (j'avais mis un fake lien)
    Même après inverser les sens, j'obtiens toujours la même erreur pour la ligne de: Ws.Run strHDLocation pourtant le fichier, je le vois bien à la position du .vbs et quand je le lance, il marche bien.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Ws.Run strHDLocation
    wscript.sleep 5000
    If objFSO.Fileexists(strHDLocation) Then objFSO.DeleteFile strHDLocation 'Effacer le fichier téléchargé

Discussions similaires

  1. procedure execute immediate problème plantage
    Par nathieb dans le forum SQL
    Réponses: 21
    Dernier message: 08/10/2007, 10h34
  2. pb 'erreur d'execution 1004' problème RANGE
    Par rpauquet dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 05/07/2007, 15h38
  3. meilleur "DELETE" , problème de suppression ?
    Par floritab dans le forum DB2
    Réponses: 2
    Dernier message: 20/05/2007, 14h58
  4. [Executable][Debutant] Problème
    Par GyZmoO dans le forum C
    Réponses: 12
    Dernier message: 17/04/2006, 20h10
  5. Requête DELETE problème de WHERE ... ???
    Par snoopy69 dans le forum Access
    Réponses: 4
    Dernier message: 21/11/2005, 11h19

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