Bonjour

Problématique : HTA/WSH : Ouvrir un fichier, et envoyer le contenu ligne à ligne dans une fenêtre avec iframe

Langage : HTA ou WBS ou WSH

J'arrive désormais à ouvrir un fichier texte, lire son contenu et l'afficher dans une textbox ou multibox.

Je voudrais ensuite envoyer le contenu du fichier dans une page web dans laquelle il y a une iframe (je connais le nom via le code source), et valider ligne à ligne.

J'arrive avec sendkeys à me déplacer dans l'iframe donnée, mais c'est très lourd et assez capricieux quand à l'exactitude du ciblage.

Je pense que je dois passer par une boucle avec les contrôles d'I/O pour un fichier pour parser chaque ligne, mais c'est comment envoyer les lignes dans l'iframe qui me pose problème.

Si quelqu'un a une idée ?

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
108
109
110
111
112
113
114
115
116
117
118
119
<HTA:APPLICATION 
SCROLL="no"
BORDER="thin"
CAPTION="yes"
ICON="favicon.ICO"
CONTEXTMENU="no"
SELECTION="yes"
WINDOWSTATE="normal"
SINGLEINSTANCE="yes"
SYSMENU="yes"
>
<html>
<TITLE>Gestion_OTR</TITLE>
<script language='jscript'>
function init(){
self.resizeTo(900,900);
fso=new ActiveXObject("Scripting.FileSystemObject");
hname=document.getElementById("BTfn");
hedit=document.getElementById("EDIT");
}

function BTo(){
hfile = fso.OpenTextFile(hname.value, 1, false, 0);
hedit.innerText = hfile.ReadAll();
hfile.Close();
}

function BTs(data){
hfile = fso.OpenTextFile(hname.value, 2, false, 0);
hfile.Write(hedit.innerText);
hfile.Close();
}
</script>
<script language="vbscript">
Sub Check
Set MonShell=CreateObject("wscript.Shell")
MonShell.Run "http://xxx.xxx.xxx.xxx/html/MMC/MMC_index.php"
'Attente que la page soit ouverte avec l'invite de session puis valider le bouton OK
WaitSeconds 1
MonShell.AppActivate "Connexion à"
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{ENTER}", False 'RETURN
WaitSeconds 3
'Attendre que la connexion soit établie et on positionne la fenêtre sur tout l'écran
MonShell.AppActivate "VA06 "
MonShell.SendKeys "%", False 'ALT KEY
MonShell.SendKeys " ", False 'SPACE KEY
MonShell.SendKeys "{DOWN}", False 'FLECHE BAS
MonShell.SendKeys "{DOWN}", False 'FLECHE BAS
MonShell.SendKeys "{ENTER}", False 'RETURN
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "{TAB}", False 'TAB
MonShell.SendKeys "Commandes issues du fichier texte à terme;", False 'RETURN
MonShell.SendKeys "{ENTER}", False 'RETURN
End Sub

Sub WaitSeconds (intNumSecs) 
    ' Because WScript.Sleep () is not available in HTA 
    ' scripts, invoke a VBScript file to do the waiting. 
 
    Dim strScriptFile, strCommand, intRetcode, objWS 
 
    If intNumSecs <= 0 Then Exit Sub 
 
    Set objWS = CreateObject ("WScript.Shell") 
 
    strScriptFile = "%temp%\wait" & intNumSecs & "seconds.vbs" 
 
    strCommand = "cmd /c ""echo WScript.Sleep " & intNumSecs * 1000 & " >" & strScriptFile & _ 
                "&start /wait """" wscript.exe " & strScriptFile & """" 
 
    intRetCode = objWS.Run (strCommand, 0, True) 
 
    If intRetCode = 0 Then Exit Sub 
 
    LogLine "ERROR " & CStr (intRetCode) & " DURING WAITSECONDS PROCEDURE" 
End Sub 

</script>

<script>

</script>
<body onload="init();" bgColor=#E80000>
<input id='BTfn' type=file Value='search'/>
<input id='BTo' onclick='BTo();' type=button value='Ouvrir' />
<input id='BTs' onclick='BTs();' type=button value="Sauver" />
<B>&nbsp&nbspChargement de l'OTR</B>
<DIV>
<textarea id="EDIT" rows="40" cols="104" name="EDIT" wrap="hard">
</textarea>
</DIV>
<P></P>
<input id='Check' onclick='Check()' type=button value="Checker OTR" />
<input id='Check' onclick='Frame();' type=button value="Frame" />
</body>
</html>

Merci