Ouvrir image dans une fenêtre en VBS

Résolu
PetitMinou12 Messages postés 86 Statut Membre -  
PetitMinou12 Messages postés 86 Statut Membre -
Bonjour, je souhaiterais ouvrir une image dans une fenêtre , j'ai donc chercher sur des forum et j'ai trouvé sa :

Set objExplorer = CreateObject("InternetExplorer.Application")

With objExplorer
.Navigate "about:blank"
.ToolBar = 0
.StatusBar = 0
.Left = 500
.Top = 50
.Width = 1000
.Height = 1000
.Visible = 1
.Document.Title = "Test"
.Document.Body.InnerHTML = _
"<img src='C:\Users\admin\Desktop\ProgDev\1.jpg' height=1000 width=1000>"
End With


Je souhaite supprimer le chemin d'accès pour ouvrir l'image dans le dossier actuel pour que je puisse par la suite envoyer mon projet compiler.

4 réponses

  1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
     
    dim fso
    dim scriptdir
    dim src_path
    dim src
    set fso = CreateObject("Scripting.FileSystemObject")
    ' directory in which this script is currently running
    scriptdir = fso.GetAbsolutePathName(".")
    
    src_path = scriptdir & "\1.jpeg"
    
    With objImg
        .Navigate "about:blank"
        .ToolBar = 0
        .StatusBar = 0
        .Left = 500
        .Top = 50
        .Width = 1000
        .Height = 1000
        .Visible = 1
        .Document.Title = "Test"
        .Document.Body.InnerHTML = _
            "<img src='" & src_path & "' height=1000 width=1000>"
    End With
    

    1
    1. PetitMinou12 Messages postés 86 Statut Membre 5
       
      J'ai adapté le programme et sa marche merci ^^
      0
  2. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
     
    Bonjour,

    pour récupérer le chemin du script
    scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1)
    

    Il ne te reste qu'à concaténer dans ta balise src
    0
  3. PetitMinou12 Messages postés 86 Statut Membre 5
     
    Je ne vois pas ou je dois insérée cette ligne et ou je définie mon image :/
    0
    1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
       
      Tu ne vois pas où est défini l'image ?
      Il n'y a pas beaucoup de lignes dans le code pourtant..
      Regarde là
      src='C:\Users\admin\Desktop\ProgDev\1.jpg' height=1000 width=1000>"
      
      
      0
  4. PetitMinou12 Messages postés 86 Statut Membre 5
     
    Oui mais sa je sais x) ce que je souhaite c'est connaître comment mettre la ligne pour inséré l'image
    0
    1. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831
       
      0
      1. PetitMinou12 Messages postés 86 Statut Membre 5 > jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention  
         
        J'ai essayé
        "<img src='scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & \1.jpg' height=1000 width=1000>"
        
        "<img src='scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & 1.jpg' height=1000 width=1000>"
        
        "<img src= scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & \1.jpg height=1000 width=1000>"
        
        "<img src= scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & 1.jpg height=1000 width=1000>"
        
        "<img src=scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & \1.jpg height=1000 width=1000>"
        
        "<img src=scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) & 1.jpg height=1000 width=1000>"
        


        Et aussi

        Set objExplorer = CreateObject("InternetExplorer.Application")
        scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1)
        
        With objExplorer
            .Navigate "about:blank"
            .ToolBar = 0
            .StatusBar = 0
            .Left = 500
            .Top = 50
            .Width = 1000
            .Height = 1000
            .Visible = 1
            .Document.Title = "Test"
            .Document.Body.InnerHTML = _
                "<img src=''' & scriptdir & '\1.jpg'' height=1000 width=1000>"
        End With
        


        et même un truc foireux crée par moi même :

        Set objImg = CreateObject("InternetExplorer.Application")
        Set objCurrent = CreateObject("WScript.Shell")
        actualdir = objCurrent.CurrentDirectory
        
        
        With objImg
            .Navigate "about:blank"
            .ToolBar = 0
            .StatusBar = 0
            .Left = 500
            .Top = 50
            .Width = 1000
            .Height = 1000
            .Visible = 1
            .Document.Title = "Test"
            .Document.Body.InnerHTML = _
                "<img src=''' & actualdir & '1.jpg'' height=1000 width=1000>"
        End With


        Et aucun ne marche :/

        Edit: ajout du langage dans les balises de code
        0
      2. jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention   4 831 > PetitMinou12 Messages postés 86 Statut Membre
         
        avec des double quotes au lieu des apostrophes ca fonctionnera mieux je pense.
        "src='" & scriptdir & "1.jpeg'
        
        0
      3. PetitMinou12 Messages postés 86 Statut Membre 5 > jordane45 Messages postés 30427 Date d'inscription   Statut Modérateur Dernière intervention  
         
        Oui sauf que quand je définis :
        Set objImg = CreateObject("InternetExplorer.Application")
        scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1)


        Il me fait une erreur
        0