【问题标题】:How to open batch file console window in a specific location of screen如何在屏幕的特定位置打开批处理文件控制台窗口
【发布时间】:2018-11-01 21:33:14
【问题描述】:

我想在屏幕上的特定位置打开批处理文件的控制台窗口。我在 Google 中搜索过,但没有找到解决方案。我需要四个小控制台窗口,在屏幕的每个角落一个。

【问题讨论】:

标签: windows batch-file cmd windows-console


【解决方案1】:
@echo off
setlocal

if /i "%~1" == "/4way" (
    console4way "%~f0" %*
    exit /b
)

echo Running %*

console4way

#pragma compile(Out, console4way.exe)

Global $aPid[4]

; Run ComSpec (usually set as CMD) with arguments for the 1st instance.
$aPid[0] = Run('"' & @ComSpec & '" /k ' & StringReplace($CMDLINERAW, '/4way', '', 1))

For $i1 = 1 To 3
    $aPid[$i1] = Run('"' & @ComSpec & '"')
Next

; Give time for all windows to display.
Sleep(500)

; Get list of all console class windows.
$aWinList = WinList('[CLASS:ConsoleWindowClass]')

For $i1 = 1 To UBound($aWinList) -1
    ; Get current window handle from the list.
    $hWindow = $aWinList[$i1][1]

    ; Get position and sizes of current window.
    $aPos = WinGetPos($hWindow)

    ; Move windows if process id matches.
    Switch WinGetProcess($hWindow)
        Case $aPid[0]
            WinMove($hWindow, '', 0, 0)
        Case $aPid[1]
            WinMove($hWindow, '', @DesktopWidth - $aPos[2], 0)
        Case $aPid[2]
            WinMove($hWindow, '', 0, @DesktopHeight - $aPos[3])
        Case $aPid[3]
            WinMove($hWindow, '', @DesktopWidth - $aPos[2], @DesktopHeight - $aPos[3])
    EndSwitch
Next

单独的批处理文件似乎无法完成这项任务 外部援助。

您可能需要能够处理 4 个窗口的东西 手柄并将它们移动到位置。 这4个窗口可能需要通过进程ID来识别 以确保处理正确的窗口。

console4way的代码是AutoIt3。

批处理文件,如果以/4way 作为第一个参数执行, 将执行console4way.exe。 4个控制台进程将 执行并且会发生短暂的睡眠以允许窗口 出现。 WinList 将按类获取控制台窗口。 每个窗口句柄用于获取位置、大小和进程 ID。 由于每个进程ID都匹配,当前窗口移动到 指定的桌面角上的位置。

没有指定窗口的宽度和高度。 WinMove 允许另外 2 个宽度和高度参数。 $aPos[2]$aPos[3] 是 当前控制台窗口。

执行带有/4way参数的批处理文件到 启动批处理文件以执行console4way, 否则它将在没有console4way 的情况下执行。 您可以在 /4way 参数之后添加更多参数 如果您想将参数传递给要使用的批处理文件。

console4way.au3 编译为可执行文件以匹配操作系统的位数 以便它执行相同环境的 ComSpec。


关于console4way

console4way 是执行console4way.exe 的命令。 您可以将 au3 脚本命名为 console4way.au3 (这是一个包含上述代码的文本文件)。 使用au3脚本文件编译console4way.exe 并提供说明。

编译后,您只需要批处理文件和 console4way.exe 在同一路径并执行 要测试的批处理文件。 您可以存储 au3 脚本并稍后使用 如果你想重新编译或更新代码。


编译说明console4way.au3

使用安装程序:

  1. 下载AutoIt3并安装。
  2. 右键单击console4way.au3 并选择 Compile Script (x64) 用于 64 位操作系统,否则 Compile Script (x86) 用于 32 位操作系统。
  3. 在同一目录中,您现在应该有一个console4way.exe

或带拉链:

  1. 下载AutoIt3并解压。
  2. 导航到install\Aut2Exe 并执行Aut2Exe.exe。 如果在 64 位操作系统上,您可以改为执行 Aut2Exe_x64.exe。 无论是编译成 x86 还是编译成 x64 可执行文件都一样。
  3. Source 输入是console4way.au3 的路径。
  4. Destination 输入留空,以便编译为 与脚本相同的目录。 .exe 单选按钮应该被选中。
  5. 选中 Compile for System x64 复选框以进行 64 位编译。
  6. 点击Convert按钮进行编译。
  7. 在同一目录中,您现在应该有一个console4way.exe

console4way.exe 将是一个自包含的可执行文件,可以 在没有安装 AutoIt 的操作系统上执行。

附加

查看有关 Compiling 使用 Aut2Exe 的脚本的帮助页面。

【讨论】:

  • 感谢 Micheal 的回答,但是我仍然对实现代码有点困惑,你能解释一下如何实现这个代码,我的意思是,console4way 是一个单独的文件,console4way.exe 是什么,请告诉我如何实现你的代码。
  • 我添加了 关于 console4way编译说明 部分来解决您在评论中提到的问题。
猜你喜欢
  • 2014-12-03
  • 2012-11-24
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多