Board logo

标题: [VBS]HTA里如何脚本延迟? [打印本页]

作者: kich     时间: 2007-10-28 20:47    标题: [VBS]HTA里如何脚本延迟?

HTA里如何脚本延迟?
  vbs里是wscript.sleep

hta 里如何做到呢?
作者: abcd     时间: 2007-10-28 21:09
试试setTimeout吧
作者: kich     时间: 2007-10-29 16:22
能不能给点详细使用方法,网上不好找,找了好多都是php什么的
作者: abcd     时间: 2007-10-29 16:25
setTimeout Method  Internet Development Index

--------------------------------------------------------------------------------

Evaluates an expression after a specified number of milliseconds has elapsed.

Syntax

iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])
Parameters

vCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed.
iMilliSeconds Required. Integer that specifies the number of milliseconds.
sLanguage Optional. String that specifies one of the following values: JScript Language is JScript.
VBScript Language is VBScript.
JavaScript Language is JavaScript.


Return Value

Integer. Returns an identifier that cancels the evaluation with the clearTimeout method.


你没有《DHTML 手册》这本电子书吗?
作者: abcd     时间: 2007-10-29 16:26
MSDN里也有说明的

window.setTimeout("alert('Hello, world')", 1000);
作者: zh159     时间: 2007-10-29 17:10
在HTA里,好像setTimeout并不能完全替代wscript.sleep,wscript.sleep是在延时后再执行下一行命令,而setTimeout是延时执行另一条命令,下一行的命令并不能延时。
目前我还没发现代替wscript.sleep的命令,只能用While...Wend 来计时,缺点是占用资源高
作者: sonicandy     时间: 2007-10-29 21:09
我觉得可以把整个过程拆开成链表的形式
A->B->C
然后用用SetTimeout来调用
call A()

sub A()
  '...
  hB = settimeout("B",1000)
end
sub B()
  '...
  hC = settimeout("C",1000)
end
sub C()
  '...
end
作者: kich     时间: 2007-10-30 19:55
可以不可以这样?只是个思路.
在HTA里,用ws.run运行 wscript.exe 让他执行一句wscript.sleep 3000 ,当然这里的ws.run后面的语句加上 true等待执行完毕再运行下行代码,这样就实现HTA延迟.
不知道这样行否?(我是楼主)
作者: sonicandy     时间: 2007-10-30 21:28
楼上的意思应该是
hta->(bat)->vbs 对吧?
<script language="vbscript">
set fso = createobject("scripting.filesystemobject")
set stream = fso.opentextfile("sleep.vbs",2,true)
call stream.write("call wscript.sleep(1000)")
call stream.close()
set shell = createobject("wscript.shell")
call shell.run("sleep.vbs",0,true)
call msgbox("hello world!")
</script>
[ Last edited by sonicandy on 2007-10-30 at 09:36 PM ]
作者: kich     时间: 2007-10-30 22:06
谢谢,谢谢,借助于您的脚本,写下以下HTA,测试可以等待,但效果不是很好,会有点漏斗按钮.
可以进一步把这个文件写进temp目录下,然后进行文件属性的隐藏(我没搞这操作)
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>My HTML Application</title>
<script language="vbscript">
Sub sleep(t)
  OpFile 1,t
  CreateObject("WScript.Shell").run "sleep.vbs",0,True
  msgbox("hello world!")
  OpFile 0,0
End Sub
Sub OpFile(n,t)
  Set fso=createobject("scripting.filesystemobject")
  If n=1 Then
    Set stream = fso.opentextfile("sleep.vbs",2,true)
        stream.write "wscript.sleep("&t&")"
        stream.close()
    Set stream=Nothing
  Else
    fso.DeleteFile "sleep.vbs"
  End If
  Set fso=Nothing
End Sub

</script>
<hta:application
        applicationname="MyHTA"       
        border="dialog"
        borderstyle="normal"
        caption="My HTML Application"
        contextmenu="no"
        icon="myicon.ico"
        maximizebutton="no"
        minimizebutton="yes"
        navigable="no"
        scroll="no"
        selection="no"
        showintaskbar="yes"
        singleinstance="yes"
        sysmenu="yes"
        version="1.0"
        windowstate="normal"
>
</head>
<body>
<input class="button" TYPE=BUTTON value="TestButton" name="btnTestButton"  onClick="sleep(3000)">

</body>
</html>

作者: kich     时间: 2007-10-30 22:12
对于以上代码,个人提出问题,有没有这样的代码(思路):
shell.run "wscript.exe msgbox 'ok'"

也知道wscript.exe 要直接运行文件,但有没有什么程序可以直接执行 一句代码,这样可以达到:
shell.run "wscript.exe wscript.sleep(3000)"这样的功能,呵呵,遐想!

[ Last edited by kich on 2007-10-30 at 10:13 PM ]
作者: zh159     时间: 2007-10-31 02:16
试试这个:
<script language="vbscript">
Set WshShell = CreateObject("Wscript.Shell")
msgbox "延时两秒"
WshShell.run "cmd /c echo Wscript.Sleep 2000>%tmp%\Sleep.vbs&&%tmp%\Sleep.vbs&&del/q %tmp%\Sleep.vbs",vbhid,true
msgbox "OK!"
</script>

作者: kich     时间: 2007-10-31 13:17
有没有不用临时文件就可以进行脚本延迟的??
作者: zh159     时间: 2007-11-18 21:42
如果不需要高精度的,可以用:
WshShell.run "cmd /c ping -n 3 127.1>nul",vbhid,true

作者: kich     时间: 2007-11-19 08:35
进程里会有CMD闪烁,等待漏斗看了难受.
谢谢各位了,看样子还是用setTimeOut来想办法吧~~!哎
作者: zzj7251     时间: 2007-11-19 13:56
谢谢了,找了好长时间了