我正在尝试使用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>
谢谢,如果你能帮助我
答案 0 :(得分: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
注意:使用Execute
将一个数组(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)
...