【问题标题】:Restarting HTA?重新启动 HTA?
【发布时间】:2015-09-19 04:05:08
【问题描述】:

我正在寻找一些代码来让 HTA 从头开始​​重新启动。我在这个网站上看到了一个论坛,它创建了一个调用 .vbs 并循环重启的 HTA,但我希望找到能够从头开始启动 HTA 的一行或 5 行代码。

我可以做的是让脚本使用 shell.run 命令重新打开 HTA,然后将其关闭,但有没有更简洁的方法来做到这一点?

【问题讨论】:

  • 类似于 self.close() 退出应用程序的方法,只有 self.restart() 或类似的东西
  • Location.Reload True?
  • @MCND 说了什么。 HTA 基本上是网页,所以重新加载应该是你想要的。
  • 是的,效果很好。 HTML 新手(我敢肯定你能看出来),所以我并不真正了解所有的点点滴滴。谢谢!

标签: vbscript hta


【解决方案1】:

这是一个完整的示例,展示了我们如何使用 Location.Reload(True) 重新加载 HTA 文件

好的密码是9999

<HTML>
<HEAD>
<TITLE></TITLE>
<HTA:APPLICATION
APPLICATIONNAME="Access to the system © Hackoo © 2015"
BORDER="THIN"
BORDERSTYLE="NORMAL"
ICON="Explorer.exe"
INNERBORDER="NO"
MAXIMIZEBUTTON="NO"
MINIMIZEBUTTON="NO"
SCROLL="NO"
SELECTION="NO"
SINGLEINSTANCE="YES"/>
</HEAD>
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES">
<BODY TOPMARGIN="1" LEFTMARGIN="1"><CENTER><DIV><SPAN ID="ONSCR"></SPAN></DIV></CENTER></BODY>
<SCRIPT LANGUAGE="VBScript">
Option Explicit
Dim Title,ws,Voice,ErrorMsg,WelcomeMsg,MyGoodPassword,Password,Temp,Tests,ProcessEnv,UserName
Title = "Access to the system © Hackoo 2015"
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("wscript.Shell")
Set ProcessEnv = Ws.Environment("Process")
UserName = ProcessEnv("USERNAME")
Temp = WS.ExpandEnvironmentStrings("%Temp%")
Tests = Temp &"\Tests.txt"
'------------------------------------------------------------------------------------
Sub window_onload()
    CenterWindow 280,180
    Call PasswordForm()
    Call TextFocus
    Dim Count : Count = 0
    If Not objFSO.FileExists(Tests) Then
        Dim Logfile : Set Logfile = objFSO.OpenTextFile(Tests,2,True)
        Logfile.writeline Count
        Logfile.Close
    end If
   Call Kill("Explorer.exe")
   Call DisableTaskMgr()
End Sub
'------------------------------------------------------------------------------------
Sub CenterWindow(x,y)
    Dim iLeft,itop
    window.resizeTo x,y
    iLeft = window.screen.availWidth/2 - x/2
    itop = window.screen.availHeight/2 - y/2
    window.moveTo ileft,itop
End Sub
'------------------------------------------------------------------------------------
Sub PasswordForm()
    Self.document.title = "Access to the system © Hackoo 2015"
    Self.document.bgColor = "DarkOrange"
    ONSCR.InnerHTML="<center><FONT COLOR=""#FFFFFF"" SIZE=""+1"" FACE=""VERDANA,ARIAL,HELVETICA,SANS-SERIF"">Type your Password</FONT><br><br><input type=""password"" name=""PasswordArea"" size=""20"" onKeyUp=""TextFocus""><P>"_
    &"<input  type=""Submit"" STYLE=""HEIGHT:25;WIDTH:190"" value=""Access to the system"" name=""run_button""  onClick=""CheckPassword"">"
END Sub
'------------------------------------------------------------------------------------
Sub CheckPassword
    Dim NB_Tests_MAX : NB_Tests_MAX = 3
    Dim Readfile,Count,NB_Tests_Remaining,Logfile,Controle,Command,Executer,MsgNumbTests,MsgReboot
    Set Voice = CreateObject("SAPI.SpVoice")
    ErrorMsg = "ATTENTION ! ! ! "& vbcr &"The Password is Wrong ! "& vbcr &"Try Again !"
    WelcomeMsg = "Welcome again "& DblQuote(UserName) &" in your System !"
    MyGoodPassword = "9999"
    Set Readfile = objFSO.OpenTextFile(Tests,1)
    Count = Readfile.ReadAll
    Readfile.Close
    Controle = True
    While Controle
        Count = Count + 1
        NB_Tests_Remaining = NB_Tests_MAX - Count
        Set Logfile = objFSO.OpenTextFile(Tests,2,True)
        Logfile.writeline Count
        Logfile.Close
        If PasswordArea.Value <> MyGoodPassword Then
            Voice.Speak ErrorMsg
            ws.Popup ErrorMsg,"1",Title,0+16
            MsgNumbTests =  "ATTENTION !!! "&vbcr&"Bad Password and NB°of TESTS is " & Count &"."&vbCr&_
            "The remaining number of tests is "& NB_Tests_Remaining
            Voice.Speak MsgNumbTests
            MsgBox MsgNumbTests,48,Title
            Sleep(1)
            Location.Reload(True)
        end if
        If PasswordArea.Value = MyGoodPassword Then
            If objFSO.FileExists(Tests) Then objFSO.DeleteFile Tests,True
            Controle = False
            Voice.Speak WelcomeMsg
            ws.Popup WelcomeMsg,"1",Title,0+64
            Call Launch("Explorer.exe")
            Call EnableTaskMgr()
            Self.Close
            Exit Sub
        End If
        If Count = NB_Tests_MAX Then
            If objFSO.FileExists(Tests) Then objFSO.DeleteFile Tests,True
            Voice.Speak "The computer will reboot in 30 seconds !"
            MsgReboot = "The Limit number of tests is reached ! "&vbcr& "The computer will Reboot in 30 seconds !"
                       MsgBox MsgReboot,48,"The Limit number of tests is reached ! "
                       Command="cmd /c Shutdown.exe -r -t 30 -c " & chr(34) & "The computer will reboot in 30 seconds !" & chr(34)
                       Executer = WS.Run(Command,0,False)
                       window.close
        End If
            Exit Sub
        wend
    End Sub
'----------------------------------------------------------------------------------
    Sub TextFocus
        PasswordArea.Focus
    End Sub
'----------------------------------------------------------------------------------
    Sub Kill(Process)
        Dim Ws,Command,Execution
        Set Ws = CreateObject("Wscript.Shell")
        Command = "cmd /c Taskkill /F /IM "&Process&""
        Execution = Ws.Run(Command,0,False)
    End Sub
'----------------------------------------------------------------------------------
    Sub Launch(Process)
        Dim Ws,Command,Execution
        Set Ws = CreateObject("Wscript.Shell")
        Command = "cmd /c Start "&Process&""
        Execution = Ws.Run(Command,0,False)
    End Sub
'-----------------------------------------------------------------------------------
'------------------------------EnableTaskMgr----------------------------------------
    Sub EnableTaskMgr()
        Dim WshShell,System
        System="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
        Set WshShell=CreateObject("WScript.Shell")
        Wshshell.RegWrite System, "REG_SZ"
        WshShell.RegWrite System &"\DisableTaskMgr", 0, "REG_DWORD"
    End sub
'------------------------------------------------------------------------------------
'-----------------------------DisableTaskMgr-----------------------------------------
    Sub DisableTaskMgr()
        Dim WshShell,System
        System="HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\"
        Set WshShell=CreateObject("WScript.Shell")
        Wshshell.RegWrite System, "REG_SZ"
        WshShell.RegWrite System &"\DisableTaskMgr", 1, "REG_DWORD"
    End sub
'--------------------------------------------------------------------------------------
    Sub Sleep(intNumSecs)
' Because WScript.Sleep () is not available in HTA
' scripts, invoke a VBScript file to do the waiting.
        Dim strScriptFile, strCommand, intRetcode, objWS
        If intNumSecs <= 0 Then Exit Sub
        Set objWS = CreateObject ("WScript.Shell")
        strScriptFile = "%temp%\wait" & intNumSecs & "seconds.vbs"
        strCommand = "cmd /c ""echo WScript.Sleep " & intNumSecs * 1000 & " >" & strScriptFile & _
        "&start /wait """" wscript.exe " & strScriptFile & """"
        intRetCode = objWS.Run (strCommand, 0, True)
        If intRetCode = 0 Then Exit Sub
    End Sub
'---------------------------------------------------------------------------------------
    Function DblQuote(Str)
             DblQuote = Chr(34) & Str & Chr(34)
    End Function
'---------------------------------------------------------------------------------------
</SCRIPT>

【讨论】:

  • 在每次方法调用之前都不需要Call,也不需要到处都是多余的()。
  • 这里有很多代码,Hackoo。也许一个精简的例子会更好。
【解决方案2】:

在引用@MCND的评论时,要重新启动脚本,只需实现

location.reload True

在你想使用的任何事件之后

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 2015-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-21
    相关资源
    最近更新 更多