使用 vbscript 激活(置于前台)特定窗口 [英] Activating (bring to foreground) a specific window with vbscript
问题描述
我什至不知道从哪里开始我的问题,我尝试了一百件事并用谷歌搜索了几个小时,但没有发现任何有用的.(我对每一个肮脏的把戏持开放态度.)
I'm not even sure where to start with my question, I tried a hundred things and googled for hours but didn't find anything useful. (I'm open to every dirty trick.)
这是我的问题:
我有一个带有列表框的 .hta 文件,如下所示:
I have a .hta-file with a listbox that looks like this:
它列出了我的 SAP Gui 运行的所有会话/修改.
It lists all sessions/modi of my SAP Gui running.
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
If application.Connections.Count > 0 Then
Set connection = application.Children(0)
If connection.Sessions.Count > 0 Then
Set session = connection.Children(0)
End If
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
Set optGroup = Document.createElement("OPTGROUP")
optGroup.label = "Server"
'count all connected servers
ConnectionCount = application.Connections.Count
If ConnectionCount > 0 Then
Sessionlist.appendChild(optGroup)
Else
optGroup.label = "No connection here."
End If
'count all sessions per server
If ConnectionCount > 0 Then
For Each conn in application.Connections
'Text output connections and sessions
SessionCount = conn.Sessions.Count
whatIsIt = conn.Description
ConnectionFeld.innerhtml = ConnectionFeld.innerhtml & " <br> " & SessionCount & " Sessions auf " & whatIsIt
'fill listbox with all connections
Set objOption = nothing
Set optGroup = Document.createElement("OPTGROUP")
optGroup.label = conn.Description
Sessionlist.appendChild(optGroup)
i = 0
'fill listbox with all sessions
For Each sess In conn.Sessions
i = i + 1
Set objOption = Document.createElement("OPTION")
objOption.Text = "Session " & i & ": " & sess.ID
objOption.Value = sess.ID
SessionList.options.add(objOption)
Next
Next
Else
Exit Sub
End If
我的目标:当我双击该列表中的一个条目时,我的 SAP Gui 的选定实例应该会出现在前台/被激活.
My goal: When I doubleclick on one of the entries in that list, the selected instance of my SAP Gui should come to the foreground/get activated.
不幸的是,我的任务管理器只列出了一项任务,那就是SAP 登录".我打开的一个窗口也有名称SAP Logon",所有其他窗口都具有相同的名称:SAP Easy Access".
Unfortunately my taskmanager only lists one task and that is "SAP Logon". One of my opened windows also has the name "SAP Logon", all others have the same name: "SAP Easy Access".
我可以看到连接的 ID(服务器名称)和会话的 ID 的唯一方法是使用 vbscript 提取它们.(见上)
The only way I can see the IDs of the connection (servername) and the IDs of the session is via extracting them with vbscript. (see above)
有没有办法做到这一点?在尝试了一千个解决方案后,我能想到的唯一解决方法是这两个:
Is there any way to do that? The only workarounds I could think of after trying a thousand solutions are these two:
极其丑陋的解决方法:
If sessionID = sess.ID Then
Set objShell = CreateObject("shell.application")
objShell.MinimizeAll
sess.findById("wnd[0]").maximize
End If
它最小化所有窗口,然后最大化选定的 SAP 窗口.不幸的是,我的 HTA-GUI 也被最小化了,这有点糟糕.
It minimizes all windows an then maximizes the selected SAP window. Unfortunately My HTA-GUI also gets minimized which kinda sucks.
第二个想法:
以某种方式通过快捷方式获取这些可点击的东西并将其放入我的脚本或其他一些丑陋的方式中.
Somehow get to these clickable thingies by shortcut and put that in my script or some other ugly way.
您必须手动执行此操作:
By hand you have to do this:
单击那个小箭头,右键单击图标,然后左键单击名称.
Click on that little arrow, rightclick on the icon and then leftclick on the name.
有什么办法可以自动执行此操作吗?快把我逼疯了.
Is there any way to automate this? It's driving me crazy.
希望有人能帮助我,不胜感激.
Hope someone can help me, it would be GREATLY appreciated.
PS:我坐在一台权限受限的机器上,所以我可能无法使用 Windows API ish 解决方案来解决这个问题.
PS: I'm sitting on a machine with restricted rights and so I may not be able to tackle this with Windows API-ish solutions.
关于评论的
这是不可能的:
- 更改注册表项
- 创建 COM 对象
- 使用 VBScript 以外的任何东西
推荐答案
我找到了...
resizeWorkingPane
方法 - 用于更改窗口的大小 - 也适用于后台的窗口.如果更改参数,窗口会出现在前台.
The resizeWorkingPane
method - for changing the size of a window - also works on windows in the background. If you change the parameters, the window will come to the foreground.
session.findById("wnd[0]").resizeWorkingPane 300,200,false
<小时>
我必须部分撤销此功能,因为它不适用于所有窗口.我仍然不确定为什么,但有时它总是失败.尽管如此,在我看来,这是你能得到的最接近的.
I have to partially revoke this, because it doesnt work on all windows. I'm still not sure why, but it keeps failing sometimes. Still, it seems to me, that this is the closest you can get.
这篇关于使用 vbscript 激活(置于前台)特定窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!