是否有任何通过命令提示符实现这一点的方法?
cmdow
不支持“center”,您需要自己计算并将适当的值传递给/mov
。您想要在另一个框中居中一个框的公式吗? - sorpigalcmdow /?
,所有内容都将被显示出来。 - dgo我发现AutoHotKey非常适合窗口定位任务。
这是一个示例脚本。将其命名为notepad.ahk, 然后从命令行运行或双击运行它。
Run, notepad.exe
WinWait, ahk_class Notepad
WinActivate
WinMove A,, 10, 10, A_ScreenWidth-20, A_ScreenHeight-20
它将启动一个应用程序(记事本),然后调整窗口大小,使其在窗口中心具有10像素的边框。
WinMove
时,脚本已经退出了。请给我更多建议好吗?似乎autohotkey不支持多线程。谢谢。 - roachsinai我在寻找解决同样问题的过程中偶然发现了这个问题。
经过一些尝试,我找到了一个答案,它可以按照原帖作者想要的方式工作,并且非常简单易行,但不是很通用。
在桌面或其他位置创建一个快捷方式(您可以使用右键菜单中的“创建快捷方式助手”),将其设置为运行程序“cmd.exe”,并运行它。当窗口打开时,将其定位到您想要的位置。 要保存该位置,请打开属性菜单并点击“保存”。
现在,如果您想要,还可以设置其他属性,如颜色,我强烈建议将缓冲区设置为120-240的宽度,高度为9999,并启用快速编辑模式(为什么不是默认值?!)
现在你有一个可行的快捷方式。为每个您想要以不同位置打开的CMD窗口创建一个这样的快捷方式。
现在说说技巧:windows的CMD START命令可以运行快捷方式。您无法在启动之前以编程方式重新定位窗口,但至少它会出现在您想要的位置,您可以从批处理文件或其他程序中启动它(和其他程序)。
使用cmd /c与快捷方式,您可以创建一个命令,像这样一次启动所有链接的快捷方式:
cmd /c "start cmd_link1 && start cmd_link2 && start cmd_link3"
这将以单击的方式打开所有命令窗口到您喜欢的位置,并单独设置属性,如前景色、背景色、字体、管理员模式、快速编辑模式等。现在将该“链接”移到启动文件夹中,您就可以自动还原状态,而不需要任何外部程序。
这是一个相当简单直接的解决方案。它不是通用的,但我相信它将解决大多数阅读此问题的人尝试解决的问题。
最近我这样做了,所以我会在这里发布我的cmd文件:
cd /d C:\shortucts
for %%f in (*.lnk *.rdp *.url) do start %%f
exit
晚些时候编辑:我没有提到,如果运行原始的cmd /c命令时是提升的,则您的每个窗口(如果选择了提升)都可以启动提升,而无需单独重新提示您。这非常方便,因为每次我启动计算机时我都会启动3个cmd窗口和3个其他应用程序。
nircmd win move ititle "cmd.exe" 5 5 10 10
nircmd win setsize ititle "cmd.exe" 30 30 100 200
nircmd cmdwait 1000 win setsize ititle "cmd.exe" 30 30 1000 600
nircmd win setsize alltop 960 1 1920 2160
- Stefano Spinucci如果您只想在启动时或从桌面快捷方式启动,则Bill K.的答案是最优雅的。
只需打开窗口,右键单击并选择属性。 选择布局 取消选中“让系统定位窗口” 然后点击确定。
现在窗口会在您想要的位置打开。 您可以同时在其他选项卡上设置字体和窗口颜色。 棒极了。
这可能应该是在 cmdow.exe
的回答下的评论,但我写了一个简单的批处理文件,以实现对任务栏中可见的所有窗口进行相当复杂且简单的控制。
第一步是运行 cmdow /t
来显示这些窗口的列表。查看列 Image
中的图像名称,然后执行以下命令:
mycmdowscript.cmd imagename
:: mycmdowscript.cmd
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET IMAGE=%1
SET ACTION=/%2
SET REST=1
SET PARAMS=
:: GET ANY ADDITIONAL PARAMS AND STORE THEM IN A VARIABLE
FOR %%I in (%*) DO (
IF !REST! geq 3 (
SET PARAMS=!PARAMS! %%I
)
SET /A REST+=1
)
FOR /F "USEBACKQ tokens=1,8" %%I IN (`CMDOW /t`) DO (
IF %IMAGE%==%%J (
:: you now have access to the handle in %%I
cmdow %%I %ACTION% !PARAMS!
)
)
ENDLOCAL
@echo on
EXIT /b
示例用法
:: will set notepad to 500 500
mycmdowscript.cmd notepad siz 500 500
Cscript //nologo "%~DP0pos.vbs" "%~F0" 100 50
。.vbs脚本也会在执行后被删除,所以没有必要清理任何东西。REM - Position the CMD Window Using .VBS -----------------------------------------
REM == MUST BE AT The Begining of The Batch =========
IF "%~1" == "RestartedByVBS" Goto :Code
REM Create the VBScript, if not exist
IF NOT EXIST "%~DP0pos.vbs" (
(FOR /F "tokens=1*" %%a in ('findstr "^VBS:" ^< "%~F0"') do (
echo(%%b
)) > "%~DP0pos.vbs"
)
REM Start "" "%~DP0pos.vbs" "%~F0" 100 50
Cscript //nologo "%~DP0pos.vbs" "%~F0" 100 50
EXIT /B
:code
DEL /Q "%~DP0pos.vbs"
REM ------------------------------------------------------------------------------
请将您自己批处理文件的内容放在这里
最后加上这个:
REM - Position the CMD Window Using .VBS -----------------------------------------
:Pos <BatchFileName> <X_Coordinate> <Y_Coordinate>
REM This Function will take three inputs: the name of the Batch file to execute
REM and the X and Y Coordinates to Position its CMD window
VBS: Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
VBS: Set objConfig = objWMIService.Get("Win32_ProcessStartup")
VBS: objConfig.SpawnInstance_
VBS: objConfig.X = WScript.Arguments(1)
VBS: objConfig.Y = WScript.Arguments(2)
VBS: Set objNewProcess = objWMIService.Get("Win32_Process")
VBS: intReturn = objNewProcess.Create( chr(34) & WScript.Arguments(0) &chr(34)& " RestartedByVBS", Null, objConfig, intProcessID)
REM ------------------------------------------------------------------------------
祝您愉快 :)
v_cmd = c:\temp\1st_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
SetTitleMatchMode 2
SetTitleMatchMode Fast
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, 0, 0,1920,500
v_cmd = c:\temp\2nd_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, 0, 500,960,400
v_cmd = c:\temp\3rd_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, 960, 500,960,400
小修改 与 自动计算 X / Y 屏幕尺寸 [ 4 个监视器 ] 相同的代码,但也可以用于 3 / 2 个监视器。
Screen_X = %A_ScreenWidth%
Screen_Y = %A_ScreenHeight%
v_cmd = c:\temp\1st_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
SetTitleMatchMode 2
SetTitleMatchMode Fast
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, 0, 0,Screen_X/2,Screen_Y/2
v_cmd = c:\temp\2nd_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, Screen_X/2, 0,Screen_X/2,Screen_Y/2
v_cmd = c:\temp\3rd_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, 0, Screen_Y/2,Screen_X/2,Screen_Y/2
v_cmd = c:\temp\4th_Monitor.ps1
Run, Powershell.exe -executionpolicy remotesigned -File %v_cmd%
WinWait, PowerShell
Sleep, 1000
;A = Active window - [x,y,width,height]
WinMove A,, Screen_X/2, Screen_Y/2,Screen_X/2,Screen_Y/2
cmdow
启动可执行文件并移动它的窗口。 - Anton