通过HTA中的VBS恢复最小化的应用程序 [英] Restore a minimised application via VBS within an HTA

查看:153
本文介绍了通过HTA中的VBS恢复最小化的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行备份时最小化的HTA.备份完成后,我想还原HTA,但遇到了麻烦.

I have an HTA that is minimised while it carries out a backup. After this backup is complete I'd like to restore the HTA, but I'm having trouble.

我已经尝试了一些操作(如下),但是没有成功.有谁能指出我的最终解决方案?

I've tried a few things (below), but with no success. Is anyone able to point me towards a definitive solution?

首先,我试图简单地激活HTA,但这失败了.我不是专家,但是我的理解是,执行此操作应该可以在任务栏中的HTA上单击鼠标,从而将其还原-

First I tried to simply activate the HTA, but this failed. I'm no expert, but my understanding is that doing this should mimick a mouse click on the HTA in the task bar, thus restoring it -

Sub RestoreBackupHTA()

    Shell.AppActivate "Backup"

End Sub

接下来,我尝试激活HTA,然后发送密钥以还原"活动窗口,但这也失败了-

Next I tried to activate the HTA and then send the keys to "restore" the active window, but that also failed -

Sub RestoreBackupHTA()

    Shell.AppActivate "Backup"
    Shell.SendKeys "% r"

End Sub

最后,我尝试先激活HTA,然后在短暂的超时后将密钥发送到恢复"活动窗口(我发现了几篇文章,暗示这可以帮助确保HTA在发送密钥之前已完全激活)恢复它),但同样失败-

Finally I tried to first activate the HTA and then send the keys to "restore" the active window after a short timeout (I found a couple of posts suggesting this could help to ensure that the HTA was fully active before sending the keys to restore it), but again, failure -

Sub RestoreBackupHTA()

    Shell.AppActivate "Backup"
    Call window.setTimeout("RestoreBackupHTAAfterWait", 500, "VBScript")

End Sub

Sub RestoreBackupHTAAfterWait()

    '** Create a tempory Shell object (required as the global Shell object is out of scope for some reason *'
    Dim tmpShell
    Set tmpShell = CreateObject("Wscript.Shell")

    tmpShell.SendKeys "% r" ' Restore the HTA

    Set tmpShell = Nothing  ' Destroy the tmpShell object

End Sub

注释-

  1. HTA的ID为备份"(<HTA:APPLICATION ID="Backup" ... />, and so "Backup" is displayed in the title bar when it is running (and as the title in the task manager). This is why I'm using it as the title parameter for Shell.AppActivate`,并且根据
  1. The HTA has the ID "Backup" (<HTA:APPLICATION ID="Backup" ... />, and so "Backup" is displayed in the title bar when it is running (and as the title in the task manager). This is why I'm using it as thetitleparameter forShell.AppActivate`, and according to this MSDN page that should be correct.
  2. Shell is declared and set globally, thus it is available to the RestoreBackupHTA procedure in the examples above.

推荐答案

嗯.它似乎为我工作.我的窗口标题显示了hta的完整路径,因此我尝试了以下操作(使用setTimeout后):

Hmm. It seemed to work for me. My window title shows the full path to the hta, so I just tried the following (after using setTimeout):

With CreateObject("WScript.Shell")
    .AppActivate("test.hta")
    .SendKeys "% r"
End With

没有任何问题.

但是这是另一种方式.您可以使用 nircmd (总是很方便).

But here's another one way. You can use nircmd (always handy to have on hand).

CreateObject("WScript.Shell").Run "nircmd.exe win normal ititle Backup"

这将恢复标题中带有备份"的所有窗口.如果您需要更好的控制,则可以过滤多种方式(标题,类,PID等).

This will restore any windows with "Backup" in the title. You can filter many ways (title, class, PID, etc) if you need finer control.

这篇关于通过HTA中的VBS恢复最小化的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆