Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在顶部保留一个VBScript窗口,并添加一个注销按钮_Vbscript_Timer - Fatal编程技术网

在顶部保留一个VBScript窗口,并添加一个注销按钮

在顶部保留一个VBScript窗口,并添加一个注销按钮,vbscript,timer,Vbscript,Timer,我有一段脚本,用户Hackoo的courtosey,但有两个地方出了问题。首先,窗口需要保持在顶部,它不能从任务栏中退出,它需要位于屏幕的右下角(任务栏上方),并且它需要在文本下方有一个按钮,上面写着“注销”。当然,注销按钮需要注销计算机。代码如下: Option Explicit Dim Title,ws,nMinutes,nSeconds,sMessage Title = "Session Timer" Set ws = CreateObject("wscript.Shell") nMinu

我有一段脚本,用户Hackoo的courtosey,但有两个地方出了问题。首先,窗口需要保持在顶部,它不能从任务栏中退出,它需要位于屏幕的右下角(任务栏上方),并且它需要在文本下方有一个按钮,上面写着“注销”。当然,注销按钮需要注销计算机。代码如下:

Option Explicit
Dim Title,ws,nMinutes,nSeconds,sMessage
Title = "Session Timer"
Set ws = CreateObject("wscript.Shell")
nMinutes = 20
nSeconds = 0
sMessage = "<font color=Red size=2><b>You have"
'Open a chromeless window with message
with HTABox("lightBlue",100,250,0,630)
.document.title = "Session Timer"
.msg.innerHTML = sMessage
do until .done.value or (nMinutes + nSeconds < 1)
    .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" &   Right("0"&nSeconds, 2) _
    & " minutes of session time 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 "Your session time has finished. You will now be logged         off.","5",Title,0+48
'*****************************************************************
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
选项显式
暗标题、ws、N分钟、N秒、sMessage
Title=“会话计时器”
设置ws=CreateObject(“wscript.Shell”)
n分钟=20
N秒=0
sMessage=“你有”
'打开带有消息的无铬窗口
带有HTABox(“浅蓝色”,100250,0630)
.document.title=“会话计时器”
.msg.innerHTML=sMessage
直到.done.value或(n分钟+n秒<1)
.msg.innerHTML=sMessage&“
”&n分钟&“:”&Right(“0”&n秒,2)_ &“剩余会话时间的分钟数
” wsh.sleep 1000'毫秒 N秒=N秒-1 如果N秒小于0,则 如果nMinutes>0,则 n分钟=n分钟-1 N秒=59 如果结束 如果结束 环 .done.value=true .结束 以 ws.Popup“您的会话时间已结束。您现在将注销。”,“5”,标题,0+48 '***************************************************************** 函数HTABox(sBgColor,h,w,l,t) 美国国家公路交通管理局、挪威国家公路交通管理局、挪威国家公路交通管理局 随机化:nRnd=Int(1000000*rnd) sCmd=“mshta.exe”javascript:{new”_ &ActiveXObject(“InternetExplorer.Application”)_ &.PutProperty(“&nRnd&”,窗口)_ &window.resizeTo(&w&“,&h&”)_ &window.moveTo(“&l&”、“&t&”}” 使用CreateObject(“WScript.Shell”) .运行sCmd,1,错误 dountil.AppActivate(“javascript:{new”):WSH.sleep 10:loop 以“WSHShell”结尾 对于CreateObject(“Shell.Application”).windows中的每个IE 如果是IsObject(即GetProperty(nRnd)),则 设置HTABox=IE.GetProperty(nRnd) 即退出 HTABox.document.title=“HTABox” HTABox.document.write_ "" _ & "" _ & "" _ &“
”_ & "" HTABox.btn1.focus 退出功能 如果结束 下一个 MsgBox“未找到HTA窗口。” 退出 端函数
谢谢,
Matthew

请注意,我不认为我们可以始终保持在顶部,但无论如何,请尝试进行此修改,现在您希望它位于右角而不是左侧,我添加了注销会话的按钮:

Option Explicit
Dim Title,ws,nMinutes,nSeconds,sMessage,Command,Executer
Title = "Session Timer"
Set ws = CreateObject("wscript.Shell")
nMinutes = 20
nSeconds = 0
sMessage = "<font color=Red size=2><b>You have"
'Open a chromeless window with message
with HTABox("lightBlue",130,300,1070,600)
.document.title = "Session Timer"
.msg.innerHTML = sMessage
do until .done.value or (nMinutes + nSeconds < 1)
    .msg.innerHTML = sMessage & "<br>" & nMinutes & ":" &   Right("0"&nSeconds, 2) _
    & " minutes of session time 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 "Your session time has finished. You will now be logged off.","5",Title,0+48
Command ="cmd /c Shutdown.exe -l -f"
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=' Log Off ' "_
            & "onclick=done.value=true><center></body>"
            HTABox.btn1.focus
            Exit Function
        End If
    Next
    MsgBox "HTA window not found."
    wsh.quit
End Function
选项显式
Dim标题、ws、N分钟、N秒、sMessage、命令、Executer
Title=“会话计时器”
设置ws=CreateObject(“wscript.Shell”)
n分钟=20
N秒=0
sMessage=“你有”
'打开带有消息的无铬窗口
带有HTABox(“浅蓝色”,1303001070600)
.document.title=“会话计时器”
.msg.innerHTML=sMessage
直到.done.value或(n分钟+n秒<1)
.msg.innerHTML=sMessage&“
”&n分钟&“:”&Right(“0”&n秒,2)_ &“剩余会话时间的分钟数
” wsh.sleep 1000'毫秒 N秒=N秒-1 如果N秒小于0,则 如果nMinutes>0,则 n分钟=n分钟-1 N秒=59 如果结束 如果结束 环 .done.value=true .结束 以 ws.Popup“您的会话时间已结束。您现在将注销。”,“5”,标题,0+48 Command=“cmd/c Shutdown.exe-l-f” Executer=WS.Run(命令,0,False) '***************************************************************** 函数HTABox(sBgColor,h,w,l,t) 美国国家公路交通管理局、挪威国家公路交通管理局、挪威国家公路交通管理局 随机化:nRnd=Int(1000000*rnd) sCmd=“mshta.exe”javascript:{new”_ &ActiveXObject(“InternetExplorer.Application”)_ &.PutProperty(“&nRnd&”,窗口)_ &window.resizeTo(&w&“,&h&”)_ &window.moveTo(“&l&”、“&t&”}” 使用CreateObject(“WScript.Shell”) .运行sCmd,1,错误 dountil.AppActivate(“javascript:{new”):WSH.sleep 10:loop 以“WSHShell”结尾 对于CreateObject(“Shell.Application”).windows中的每个IE 如果是IsObject(即GetProperty(nRnd)),则 设置HTABox=IE.GetProperty(nRnd) 即退出 HTABox.document.title=“HTABox” HTABox.document.write_ "" _ & "" _ & "" _ &“
”_ & "" HTABox.btn1.focus 退出功能 如果结束 下一个 MsgBox“未找到HTA窗口。” 退出 端函数
谢谢!这太棒了。我希望其他人会觉得这很有用。