删除按钮并在 hta-vbscript 中使用下拉框

remove button and use dropdown box in hta-vbscript

我对 hta 和 vbscript 还很陌生。我从互联网上下载了一个 **hta** 脚本来延迟计算机的重启。

30分钟、45分钟、60分钟等延迟按钮。 我想使用 combobox(Dropdown box) 而不是按钮。

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

下面是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>

编辑

I can show dropdown box on the hta application but i don't know how to manage vbscript with that.

基本上您应该从 SELECT 元素中获取值。 假设 SELECT 元素的名称为 btnDelay。 要获得 btnDelay 的值,您应该使用 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>