Open image in a window using VBS

Solved
PetitMinou12 Posted messages 86 Status Member -  
PetitMinou12 Posted messages 86 Status Member -
Bonjour, je souhaiterais ouvrir une image dans une fenêtre, j'ai donc cherché sur des forums et j'ai trouvé ça :

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='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 compilé.

4 answers

jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
 dim fso dim scriptdir dim src_path dim src set fso = CreateObject("Scripting.FileSystemObject") ' répertoire dans lequel ce script est en cours d'exécution 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 


--
Best regards,
Jordane
1
PetitMinou12 Posted messages 86 Status Member 5
 
I adapted the program and it works, thanks ^^
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
Hello,

to retrieve the script path
 scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1) 

All you need to do is concatenate it in your src tag

--
Best regards,
Jordane
0
PetitMinou12 Posted messages 86 Status Member 5
 
I don't see where I need to insert this line and where I define my image :/
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
You don't see where the image is defined?
There aren't many lines in the code anyway..
Look here
 src='C:\Users\admin\Desktop\ProgDev\1.jpg' height=1000 width=1000>" 
0
PetitMinou12 Posted messages 86 Status Member 5
 
Yes, but I know that x) what I would like to know is how to write the line to insert the image.
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830
 
0
PetitMinou12 Posted messages 86 Status Member 5 > jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention  
 
```html I tried
 "<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>" 


And also

 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 


and even a messed up thing created by myself:

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


And none of them work :/

Edit: added the language in the code tags ```
0
jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention   4 830 > PetitMinou12 Posted messages 86 Status Member
 

 "src='\" & scriptdir & "1.jpeg'" 
0
PetitMinou12 Posted messages 86 Status Member 5 > jordane45 Posted messages 30426 Registration date   Status Moderator Last intervention  
 
Yes, except that when I define:
Set objImg = CreateObject("InternetExplorer.Application")
scriptdir = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.lastIndexOf(WScript.ScriptName)-1)


I get an error
0