我是 vbs 的新手,并尝试制作一个启动 exe 或服务的脚本,每个脚本之间有一个定义的延迟,我将它混合在一个 hta 文件中并且效果很好。但我需要在多台计算机上使用它,然后,需要使这个脚本更容易配置,并考虑添加一个配置文件 .csv。但是我没有成功让我的脚本一个接一个地读取我的 csv 的所有行。
我的脚本工作:
<!-- ----- ExeScript Options Begin ----- ScriptType: window,invoker DestDirectory: temp Icon:
C:\Users\stream\Desktop\startapp.bmp File:
C:\Users\stream\Desktop\startapp.bmp OutputFile:
C:\Users\stream\Desktop\test.exe ----- ExeScript Options End -----
-->
<head>
<title>Start App</title>
<HTA:APPLICATION
APPLICATIONNAME="Start App"
ID="startapp"
VERSION="1.3"
MAXIMIZEBUTTON="no"
ICON="startapp.ico"
SINGLEINSTANCE="yes"
SELECTION="no"/>
<SCRIPT TYPE="text/javascript">
window.resizeTo(350,275);
window.moveTo(2,720);
</SCRIPT>
<SCRIPT language="vbscript">
Dim WshShell
Sub Window_onLoad
StartTimer
End Sub
Sub StartTimer
MonTimer0 =window.setTimeOut ("welcome", 5000, "VBScript") 'Appel de MonScript
MonTimer1 = window.setTimeOut ("Start01", 35000, "VBScript") 'Appel de MonScript
MonTimer2 = window.setTimeOut ("Start02", 45000, "VBScript") 'Appel de MonScript
MonTimer8 = window.setTimeOut ("Startend", 55000, "VBScript") 'Appel de MonScript
MonTimer9 = window.setTimeOut ("Startclose", 65000, "VBScript") 'Appel de MonScript
End sub
Sub Welcome
S = SetTimeOut("MaSub (""Vos applications vont se lancer dans un instant... Veuillez patienter..."")", 100)
End Sub
Sub Start01
Set WshShell = CreateObject ("Wscript.Shell")
WshShell.Run """C:\Program Files\soft1\soft1.exe"""
S = SetTimeOut("MaSub (""soft1 a bien été lancé !"")", 100)
End Sub
Sub Start02
Set WshShell = CreateObject ("Wscript.Shell")
WshShell.Run """C:\Program Files\soft2\soft2.exe"""
S = SetTimeOut("MaSub (""Soft2 a bien été lancé !"")", 100)
End Sub
Sub Startend
S = SetTimeOut("MaSub (""Toutes les applications ont été correctement lancées ! StartApp va se fermer..."")", 100)
End Sub
Sub Startclose
window.close()
End Sub
Set WshShell = nothing
</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>
现在我正在尝试制作的代码... csv 文件:
MonTimer0;Start01;5000;"C:\Program Files\soft1\soft1.exe";soft1 a bien été lancé !
MonTimer1;Start02;10000;"C:\Program Files\soft1\soft2.exe";soft2 a bien été lancé !;
hta 文件:
<!-- ----- ExeScript Options Begin -----
ScriptType: window,invoker
DestDirectory: temp
Icon: D:\Bureau\startapp.bmp
File: D:\Bureau\startapp.bmp
OutputFile: D:\Bureau\test.exe
----- 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">
Dim FSO, LeFichier
Dim CheminNomFichier, MeTbl, PourTbl, T
Set fso = CreateObject("Scripting.FileSystemObject")
CheminNomFichier = "D:\Mes documents\PROGRAMMATION\Startapp\StartApp.csv"
Set LeFichier = fso.OpenTextFile(CheminNomFichier,1)
PourTbl = LeFichier.ReadAll
LeFichier.Close
Dim Var0, Var1, Var2, Var3, Var4
' .......................
'PourTbl contient: "un;deux;trois;quatres;cinqiéme et dernier;"
MeTbl = split(PourTbl,";")
for T =0 to ubound(MeTbl)-1
next
var0 = MeTbl(0)
var1 = MeTbl(1)
var2 = MeTbl(2)
var3 = MeTbl(3)
var4 = MeTbl(4)
Dim WshShell
Sub Window_onLoad
StartTimer
End Sub
Sub StartTimer
var0 =window.setTimeOut ( var1 , var2, "VBScript") 'Appel de MonScript
End sub
Sub var1
Set WshShell = CreateObject ("Wscript.Shell")
WshShell.Run WshShell.ExpandEnvironmentStrings(var3)
S = SetTimeOut("MaSub (var4)", 100)
End Sub
Sub Startend
S = SetTimeOut("MaSub (""toutes les applications ont été correctement lancées !"")", 100)
End Sub
Sub Startend
window.close()
End Sub
Set WshShell = nothing
</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>
运行 hta 它告诉我第 68 行 [ sub (var1) ] 上的语法错误并且什么都不做......
如果你能帮助我,那就太好了!nb:如果我的英语有点糟糕,我很抱歉,我已经很久没有使用这种语言了。