0

我正在尝试使用 vbs 和 csv 配置文件创建一个 hta 脚本,以便在每次启动之间有一个延迟的启动器。然后,它可以工作,但有一些问题:当我运行 hta 文件时,所有软件都是同时启动的,一开始。在显示所有文本后,尊重延迟。第一个目标是使软件在每次启动后都显示延迟和每个文本。最后一个问题是在读取 csv 文件结束时,vbs 脚本似乎停止并执行,hta 不会自行关闭。

.csv 文件:

        Horloge,Nom,Delai,Soft,Resultat
MonTimer1,Start01,10000,C:\Program Files\IZArc\IZArc.exe,Izarc a bien été lancé
MonTimer2,Start02,15000,C:\Program Files\Moffsoft FreeCalc\MoffFreeCalc.exe,La calculatrice a bien été lancée
MonTimer3,Start03,20000,,All Tasks have been executed !
MonTimer4,Startfin,25000,,hta will now close !  

hta 文件:

<!-- ----- ExeScript Options Begin -----
 ScriptType: window,invoker
 DestDirectory: temp
 Icon: D:\Bureau\startapp.bmp
 File: D:\Bureau\startapp.bmp
 ----- ExeScript Options End ----- -->

<head>
<title>Start App</title>

<HTA:APPLICATION
  APPLICATIONNAME="Start App"
  ID="startapp"
  VERSION="1.2"
  MAXIMIZEBUTTON="no"
  ICON="startapp.ico"
  SCROLL="no"
  SINGLEINSTANCE="yes"
  SELECTION="no"/>

<SCRIPT TYPE="text/javascript">
window.resizeTo(350,275);
window.moveTo(10,10);
</SCRIPT>

    <SCRIPT language="vbscript">

       Sub Window_onLoad
           StartTimer      
       End Sub

            Sub StartTimer
                MonTimer0 =window.setTimeOut ("welcome", 1000, "VBScript") 'Appel de MonScript
            End sub

                Sub Welcome
                    S = SetTimeOut("MaSub (""Vos applications vont se lancer dans un instant... Veuillez patienter..."")", 100)
                End Sub 


Dim Horloge
Dim Nom
Dim Delai
Dim Soft
Dim Resultat

Dim aVars 
aVars = Array( "Horloge", "Nom", "Delai", "Soft", "Resultat" ) 

Dim oFSO
Set oFSO = CreateObject( "Scripting.FileSystemobject" )

Const INPUT_FILE = "StartApp.csv"
Dim oStream
Dim sData
Dim aData



Set oStream = oFSO.OpenTextFile( INPUT_FILE )

oStream.SkipLine

Do While oStream.AtEndOfStream = False
    sData = oStream.ReadLine
    aData = Split( sData, "," )
    For i = 0 To UBound( aData ) 
        Execute aVars( i ) & " = " & Chr( 34 ) & aData( i ) & Chr( 34 ) 


    Next 
    'At this point all the vars referred to in aVars have the values
    'of the current record

    'START APP

    'WSCript.Echo Horloge, Nom, Delai, Soft, Resultat



Set WshShell = CreateObject ("Wscript.Shell")
WshShell.Run Chr(34) & soft

S = SetTimeOut("MaSub (" & Chr(34) & Resultat & Chr(34) & ")", Delai)   

'If oStream.AtEndOfStream = False Then
' window.close()
' End If

Loop

oStream.Close

</SCRIPT>



</head>

<Body STYLE="font:10 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" >

<p><center> <img src=".\startapp.bmp" /> </center></p>
<br/><br/><br/>

<p><center>
<span style="color:white">
<div id = D></div>

<script language = vbs>
Sub MaSub (E)
Document.All.D.innerHTML = E
ClearTimeOut S
End Sub
</script>
</center></p>

</span>
</body>
</html>

谢谢如果你能帮助我

4

1 回答 1

0

用这个代替setTimeOut

Set sh = CreateObject("WScript.Shell")

Set oStream = oFSO.OpenTextFile( INPUT_FILE )
oStream.SkipLine
Do Until oStream.AtEndOfStream
  ...
  sh.Run Chr(34) & soft & Chr(34), 0, False
  sh.Run "ping -n " & (1+Delai/1000) & " 127.0.0.1", 0, True
Loop

注意:使用Executefor 将一个数组 ( ) 中的值分配给另一个数组 ( aData) 中的变量名aVars确实非常难看,并且会使您的代码不必要地难以阅读。我强烈建议aData直接使用或使用“普通”变量赋值:

Dim Horloge, Nom, Delai, Soft, Resultat
...
Do While oStream.AtEndOfStream = False
  aData = Split(oStream.ReadLine, ",")
  Horloge  = aData(0)
  Nom      = aData(1)
  Delai    = aData(2)
  Soft     = aData(3)
  Resultat = aData(4)
  ...
于 2013-06-03T09:42:38.110 回答