本文介绍了删除按钮并在hta-vbscript中使用下拉框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 hta& vbscript .我从互联网上下载了**hta**脚本,以延迟计算机的重新启动.

I am fairly new to hta & vbscript. I have a **hta** script downloaded from internet to delay reboot of computer.

有一些延迟按钮,例如 30分钟,45分钟,60分钟等.我想使用 combobox(下拉框)代替按钮.

There are button for delay such as 30 min, 45 min, 60 min etc.I would like to use combobox(Dropdown box) instead of button.

我也希望我的vbscript可以与下拉框一起使用.

I also want my vbscript will work with dropdown box.

下面是hta的代码.

Below are the code of hta.

<html>
   <head>
    <title>Reboot Notification</title>
    <hta:application id="oMyApp"
        applicationname="Reboot Notification"
        border="dialog"
        BORDERSTYLE="normal"
        caption="yes"
        scroll="no"
        MAXIMIZEBUTTON="NO"
        MINIMIZEBUTTON="NO"
        showintaskbar="no"
        singleinstance="yes"
        SYSMENU="no"/>
    </head>

    <script language = "VBScript">
        Dim intMinutes
        Dim intSeconds
        Dim strHTAProc
        Set objShell = CreateObject("Wscript.Shell")

        Sub Window_OnLoad
            resizeto 600,450
            moveto 600,400
            intMinutes = 15
            intSeconds = 0
            GetProcessID
            'Run the RebootTimer Sub Procedure Every 1 Second
            iTimerID = window.setInterval("RebootTimer", 1000)
        End Sub

        '*** Get the HTA Application Process ID
        Sub GetProcessID
            strComputer = "."
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
            Set colProcesses = objWMIService.ExecQuery("Select Name, Handle from Win32_Process Where Name = 'mshta.exe'")
            For Each objProcess in colProcesses
                strHTAProc = objProcess.Handle
            Next
        End Sub

        '***** Update the Time to Selected Value *********
        Sub Delay30
            btnDisabled
            intMinutes = 30
            intSeconds = 0
        End Sub

        Sub Delay45
            btnDisabled
            intMinutes = 45
            intSeconds = 0
        End Sub

        Sub Delay60
            btnDisabled
            intMinutes = 60
            intSeconds = 0
        End Sub

          Sub Delay90
            btnDisabled
            intMinutes = 90
            intSeconds = 0
        End Sub

          Sub Delay120
            btnDisabled
            intMinutes = 120
            intSeconds = 0
        End Sub

          Sub Delay240
            btnDisabled
            intMinutes = 240
            intSeconds = 0
        End Sub

Function Document_onKeyDown()

    Dim alt
    alt = window.event.altKey
    Select Case window.event.keyCode
        Case 27,116
            window.event.keyCode = 0
            window.event.cancelBubble = true
            Document_onKeyDown = False
        Case 115
            If alt Then
                window.event.keyCode = 0
                window.event.cancelBubble = true
                Document_onKeyDown = False
            End If
        Case Else
            Document_onKeyDown = True
    End Select

End Function


        '*************************************************

        '*** Disable all of the Buttons Once One is Selected
        Sub btnDisabled
            btnDelay30.Disabled = True
            btnDelay45.Disabled = True
            btnDelay60.Disabled = True
            btnDelay90.Disabled = True
            btnDelay120.Disabled = True
            btnDelay240.Disabled = True
        End Sub

        Sub RebootTimer
            If intSeconds = 0 Then
                If intMinutes = 0 and intSeconds = 0 Then 'Reboot the Workstations
                    objShell.AppActivate strHTAProc
                    objShell.Run "shutdown -r -f -t 0"
                Else
                    intMinutes = intMinutes - 1
                End If
                intSeconds = 59
            Else 
                intSeconds = intSeconds - 1
            End If

            'Update the Clock 
            Clock.innerHTML = "A Reboot Will Occur in " & "<strong>" & intMinutes & ":" & Right("00" & intSeconds, 2) & "</strong>"

            'Activate the HTA Application at 1, 5, and 10 minutes to remind the user
            If intMinutes = 1 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            ElseIf intMinutes = 5 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            ElseIf intMinutes = 10 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            End If

        End Sub

    </script>

    <body onLoad="window.focus()" STYLE="filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#9BC59F', EndColorStr='#508855')">
        <h2 p style="text-align: center; "><span>Reboot Notification</h2></span></p>
        <h3 p style="text-align: center; "><span>Your Workstation Requires A Reboot</h3></span></p>
        <p style="text-align: center;"><span id="Clock"></span></p>      
        <p style="text-align: center;"><input id=btnDelay30 class="button" type="button" value="Delay 30 Minutes" name="btnDelay30" onClick="Delay30"/></p>
        <p style="text-align: center;"><input id=btnDelay45 class="button" type="button" value="Delay 45 Minutes" name="btnDelay45" onClick="Delay45"/></p>
        <p style="text-align: center;"><input id=btnDelay60 class="button" type="button" value="Delay 60 Minutes" name="btnDelay60" onClick="Delay60"/></p>
        <p style="text-align: center;"><input id=btnDelay90 class="button" type="button" value="Delay 90 Minutes" name="btnDelay90" onClick="Delay90"/></p>
        <p style="text-align: center;"><input id=btnDelay120 class="button" type="button" value="Delay 120 Minutes" name="btnDelay120" onClick="Delay120"/></p>
        <p style="text-align: center;"><input id=btnDelay240 class="button" type="button" value="Delay 240 Minutes" name="btnDelay240" onClick="Delay240"/></p>
        <p style="text-align: center; font-size:14px;"><span>If you have any questions please contact the Helpdesk at ext. ####</span></p>
    </body>

</html>

编辑

推荐答案

基本上,您应该从SELECT元素获取值.假设SELECT元素的名称为btnDelay.要获取btnDelay的值,您应该使用btnDelay.Value

Basically you should get value from SELECT element. Let's say SELECT element has name btnDelay.To get value of btnDelay you should use btnDelay.Value

享受

<html>
   <head>
    <title>Reboot Notification</title>
    <hta:application id="oMyApp"
        applicationname="Reboot Notification"
        border="dialog"
        BORDERSTYLE="normal"
        caption="yes"
        scroll="no"
        MAXIMIZEBUTTON="NO"
        MINIMIZEBUTTON="NO"
        showintaskbar="no"
        singleinstance="yes"
        SYSMENU="no"/>
    </head>

    <script language = "VBScript">
        Dim intMinutes
        Dim intSeconds
        Dim strHTAProc
        Set objShell = CreateObject("Wscript.Shell")

        Sub Window_OnLoad
            resizeto 600,550
            moveto 300,300
            intMinutes = 15
            intSeconds = 0
            GetProcessID
            'Run the RebootTimer Sub Procedure Every 1 Second
            iTimerID = window.setInterval("RebootTimer", 1000)
        End Sub

        '*** Get the HTA Application Process ID
        Sub GetProcessID
            strComputer = "."
            Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
            Set colProcesses = objWMIService.ExecQuery("Select Name, Handle from Win32_Process Where Name = 'mshta.exe'")
            For Each objProcess in colProcesses
                strHTAProc = objProcess.Handle
            Next
        End Sub

        '***** Update the Time to Selected Value *********
    Sub SetDelay
            btnDisabled
            intMinutes = btnDelay.Value
            intSeconds = 0
    End Sub

Function Document_onKeyDown()

    Dim alt
    alt = window.event.altKey
    Select Case window.event.keyCode
        Case 27,116
            window.event.keyCode = 0
            window.event.cancelBubble = true
            Document_onKeyDown = False
        Case 115
            If alt Then
                window.event.keyCode = 0
                window.event.cancelBubble = true
                Document_onKeyDown = False
            End If
        Case Else
            Document_onKeyDown = True
    End Select

End Function


        '*************************************************

        '*** Disable all of the Buttons Once One is Selected
        Sub btnDisabled
            btnDelay.Disabled = True
        End Sub

        Sub RebootTimer
            If intSeconds = 0 Then
                If intMinutes = 0 and intSeconds = 0 Then 'Reboot the Workstations
                    objShell.AppActivate strHTAProc
                    objShell.Run "shutdown -r -f -t 0"
                Else
                    intMinutes = intMinutes - 1
                End If
                intSeconds = 59
            Else 
                intSeconds = intSeconds - 1
            End If

            'Update the Clock 
            Clock.innerHTML = "A Reboot Will Occur in " & "<strong>" & intMinutes & ":" & Right("00" & intSeconds, 2) & "</strong>"

            'Activate the HTA Application at 1, 5, and 10 minutes to remind the user
            If intMinutes = 1 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            ElseIf intMinutes = 5 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            ElseIf intMinutes = 10 and intSeconds = 0 Then
                objShell.AppActivate strHTAProc
            End If

        End Sub

    </script>

    <body onLoad="window.focus()" STYLE="filter:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#9BC59F', EndColorStr='#508855')">
        <h2 p style="text-align: center; "><span>Reboot Notification</h2></span></p>
        <h3 p style="text-align: center; "><span>Your Workstation Requires A Reboot</h3></span></p>
        <p style="text-align: center;"><span id="Clock"></span></p>      
    <select size="1" name="btnDelay" onchange="SetDelay">
        <option value="30">Delay 30 Minutes
        <option value="45">Delay 45 Minutes
        <option value="60">Delay 60 Minutes
        <option value="90">Delay 60 Minutes
        <option value="120">Delay 120 Minutes
        <option value="240">Delay 240 Minutes
    </select>
        <p style="text-align: center; font-size:14px;"><span>If you have any questions please contact the Helpdesk at ext. ####</span></p>
    </body>

</html>

这篇关于删除按钮并在hta-vbscript中使用下拉框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:31