|
|
发表于 2025-4-17 08:26:27
|
显示全部楼层
Exec 和 Run 和 批处理的 start 都没有定位功能
你可以换个思路,全部登录完成后,再移动窗口大小- <# : 另存为 ANSI 编码 bat
- @echo off
- cls
- PowerShell.exe -NoProfile -ExecutionPolicy Bypass "Invoke-Expression (${%~f0} | Out-String)"
- pause
- exit /b
- #>
- Add-Type @"
- using System;
- using System.Text;
- using System.Runtime.InteropServices;
- public class WindowAdjuster {
- public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- public static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
- [DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool IsWindowVisible(IntPtr hWnd);
- [DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
- [DllImport("user32.dll")][return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
- public struct RECT {
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
- }
- public static void AdjustWindows() {
- EnumWindowsProc enumProc = new EnumWindowsProc(EnumWindowsCallback);
- EnumWindows(enumProc, IntPtr.Zero);
- }
- private static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam) {
- if (IsWindowVisible(hWnd)) {
- StringBuilder title = new StringBuilder(1024);
- int length = GetWindowText(hWnd, title, title.Capacity);
- if (length > 0) {
- RECT rect;
- if (GetWindowRect(hWnd, out rect)) {
- int width = rect.Right - rect.Left;
- int height = rect.Bottom - rect.Top;
- Console.WriteLine("Found window handle: " + hWnd.ToString()
- + ", Title: " + title.ToString()
- + ", Position: (" + rect.Left + ", " + rect.Top + ")"
- + ", Size: (" + width + "x" + height + ")");
- if (rect.Left > 0 && rect.Top > 0) {
- MoveWindow(hWnd, 144, 79, 1632, 892, true);
- }
- }
- }
- }
- return true;
- }
- }
- "@
- [WindowAdjuster]::AdjustWindows()
复制代码 这个可以显示当前所有窗口的大小和位置,并把所有窗口移动到指定坐标指定大小
你去powershell区问下怎么修改 |
|