remove button and use dropdown box in hta-vbscript

喜夏-厌秋 提交于 2020-01-06 14:53:49

问题


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

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.

I also want my vbscript will work with dropdown box.

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>

EDIT

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


回答1:


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

Enjoy

<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>


来源:https://stackoverflow.com/questions/30756868/remove-button-and-use-dropdown-box-in-hta-vbscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!