vbscript - 如何制作 VBScript 定时器

标签 vbscript timer

我需要在消息框中显示一个计时器,用 vbs 编码。消息框需要位于屏幕的左下角,开始菜单的正上方。它需要无法退出,这意味着它不能列在任务栏上(希望如此)并且没有最小化/退出按钮。它需要保持在所有其他窗口之上。它还需要从20分钟开始,以秒为单位倒计时。我希望有人能帮我解决这个问题 - 这是一个计算机实验室。

谢谢, 马修

最佳答案

尝试类似的事情:

Option Explicit
Dim Title,ws,nMinutes,nSeconds,sMessage
Title = "Counting Down to Shutdown"
Set ws = CreateObject("wscript.Shell")
nMinutes = 20
nSeconds = 0
sMessage = "<font color=Red size=2><b>Counting Down to Shutdown"
'Open a chromeless window with message
with HTABox("lightBlue",100,250,0,630)
    .document.title = "Counting Down Notification to Shutdown"
    .msg.innerHTML = sMessage
    do until .done.value or (nMinutes + nSeconds < 1)
        .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" & Right("0"&nSeconds, 2) _
        & " remaining</b></font><br>"
        wsh.sleep 1000 ' milliseconds
        nSeconds = nSeconds - 1
        if nSeconds < 0 then 
            if nMinutes > 0 then
                nMinutes = nMinutes - 1
                nSeconds = 59
            end if
        end if
    loop
    .done.value = true
    .close
end with
ws.Popup "TIME IS OVER !","5",Title,0+48 'Afficher un Popup durant 5 secondes puis on quitte le script
'Command="cmd /c Shutdown.exe -s -t 30 -c " & DblQuote("Sauvegarder votre Travail car l'ordinateur va rebooter dans 30 secondes")
'Executer = WS.Run(Command,0,False) 
'*****************************************************************
Function HTABox(sBgColor, h, w, l, t)
    Dim IE, HTA, sCmd, nRnd
    randomize : nRnd = Int(1000000 * rnd)
    sCmd = "mshta.exe ""javascript:{new " _
    & "ActiveXObject(""InternetExplorer.Application"")" _
    & ".PutProperty('" & nRnd & "',window);" _
    & "window.resizeTo(" & w & "," & h & ");" _
    & "window.moveTo(" & l & "," & t & ")}"""
    with CreateObject("WScript.Shell")
        .Run sCmd, 1, False
        do until .AppActivate("javascript:{new ") : WSH.sleep 10 : loop
        end with  'WSHShell
        For Each IE In CreateObject("Shell.Application").windows
            If IsObject(IE.GetProperty(nRnd)) Then
                set HTABox = IE.GetProperty(nRnd)
                IE.Quit
                HTABox.document.title = "HTABox"
                HTABox.document.write _
                "<HTA:Application contextMenu=no border=thin " _
                & "minimizebutton=no maximizebutton=no sysmenu=no SHOWINTASKBAR=no >" _
                & "<body scroll=no style='background-color:" _
                & sBgColor & ";font:normal 10pt Arial;" _
                & "border-Style:inset;border-Width:3px'" _
                & "onbeforeunload='vbscript:if not done.value then " _
                & "window.event.cancelBubble=true:" _
                & "window.event.returnValue=false:" _
                & "done.value=true:end if'>" _
                & "<input type=hidden id=done value=false>" _
                & "<center><span id=msg>&nbsp;</span><br>" _
                & "<input type=button id=btn1 value=' OK ' "_
                & "onclick=done.value=true><center></body>"
                HTABox.btn1.focus
                Exit Function
            End If
        Next
        MsgBox "HTA window not found."
        wsh.quit
End Function
'*****************************************************************

关于vbscript - 如何制作 VBScript 定时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29406275/

相关文章:

powershell - Powershell 中的 New-Object -ComObject 和 VB 中的 CreateObject() 有什么区别?

java - WebSphere 集群上带有 TimerManager 的单例

C#,System.Timers.Timer,每分钟与系统时钟同步运行

excel - 范围查找替换VBScript excel 编译错误缺少说明

python - 在运行 Windows 批处理文件、vbscript/wscript 或 Python 控制台脚本时将图像显示为初始屏幕

regex - 编写选择 VBScript 类及其名称的正则表达式

ios - 从同一范围调用 block /闭包

javascript - Internet Explorer 渲染问题(简单的 JS 计时器 - window.setTimeout)

android - 社交应用程序的计时器

regex - 带有字符 + 或 - 的 VBScript RegExp