VBS脚本执行后关闭控制台

时间:2016-04-25 21:17:04

标签: batch-file vbscript

我有一个多屏幕计算机系统。偶尔,由于我不明白的原因,对话框在错误的监视器上。例如,我将在监视器A中运行一个程序,并在监视器D中打开一个OK框。这非常令人沮丧。

我在这里找到了一个名为“PositionDialogs.vbs”的VBS脚本:https://www.realtimesoft.com/ultramon/scripts/

Const SNAP_TO_MONITOR = False 'set this to True to ensure dialogs aren't placed between two monitors
Const INTERVAL = 2 'number of seconds the script waits before enumerating open windows again

Set sys = CreateObject("UltraMon.System")
Set wnd = CreateObject("UltraMon.Window")
Set wndParent = CreateObject("UltraMon.Window")

'create the two maps used to store positioned windows
Set arrAdd = CreateObject("Scripting.Dictionary")
Set arrLookup = CreateObject("Scripting.Dictionary")

Do While True
    'enumerate all application windows
    For Each w In wnd.GetAppWindows(True)
        If w.HWndParent <> 0 Then
            wndParent.HWnd = w.HWndParent

            move = True
            If arrLookup.Exists(w.HWnd) = True Then move = False
            arrAdd.Add w.HWnd, 0

            If move = True Then
                If SNAP_TO_MONITOR = False Then
                    If w.Monitor <> wndParent.Monitor Then
                        w.Monitor = wndParent.Monitor
                        w.ApplyChanges 1 + 2 'WNDCHANGE_RESIZE_TO_FIT + WNDCHANGE_CLIP_TO_WORKSPACE
                    End If
                Else
                    Set parentMon = sys.Monitors(wndParent.Monitor - 1)
                    parentLeft = parentMon.WorkLeft
                    parentTop = parentMon.WorkTop
                    parentRight = parentLeft + parentMon.WorkWidth
                    parentBottom = parentTop + parentMon.WorkHeight

                    dlgLeft = w.Left
                    dlgTop = w.Top
                    dlgRight = dlgLeft + w.Width
                    dlgBottom = dlgTop + w.Height

                    If dlgLeft < parentLeft Then
                        w.Left = parentLeft
                    ElseIf dlgRight > parentRight Then
                        w.Left = parentRight - w.Width
                    End If
                    If dlgTop < parentTop Then
                        w.Top = parentTop
                    ElseIf dlgBottom > parentBottom Then
                        w.Top = parentBottom - w.Height
                    End If

                    w.ApplyChanges 0
                End If
            End If
        End If
    Next

    'swap maps, then clear arrAdd. this way we don't have entries for windows which no longer exist
    Set temp = arrLookup
    Set arrLookup = arrAdd
    Set arrAdd = temp
    Set temp = Nothing
    arrAdd.RemoveAll

    WScript.Sleep INTERVAL * 1000
Loop

将对话框移动到任何名为它的监视器。 我使用批处理文件在Windows启动时运行它,它作为一个进程运行。我的问题是显示的控制台窗口不会消失,除非我单击X关闭它。

浴室文件如下所示:

wscript PositionDialogs.vbs
exit

我认为在将脚本加载到内存后,我可以添加一些内容使其关闭?如果是这样,是什么?

1 个答案:

答案 0 :(得分:0)

aschipf是对的。 我制作了批处理文件

start PositionDialogs.vbs
exit

(使用START而不是WSCRIPT)并按预期关闭,同时该进程仍在任务管理器中运行

相关问题