在坐标处打开文件资源管理器

Open file explorer at coordinates

当我启动计算机时,我会打开几个文件资源管理器并在屏幕上对它们进行排序,以帮助加快我的工作流程。这并不费时,只是乏味,我想要一个小程序来帮我做这件事。 我知道如何打开资源管理器,但我没有看到任何位置参数。

有没有办法在一组屏幕坐标处生成文件资源管理器,或者在打开后以编程方式移动它?最好使用 python 3+,但批处理也可以。

这比我想象的更容易也更难。一切都已发表评论,如果您还有其他问题,请告诉我。这是一个 PowerShell/batch 混合脚本(因此将其保存为 .bat 文件),因为默认情况下 PowerShell 在系统上是禁用的。

<# :
:: Based on https://gist.github.com/coldnebo/1148334
:: Converted to a batch/powershell hybrid via http://www.dostips.com/forum/viewtopic.php?p=37780#p37780
:: Array comparison from 
@echo off
setlocal
set "POWERSHELL_BAT_ARGS=%*"
if defined POWERSHELL_BAT_ARGS set "POWERSHELL_BAT_ARGS=%POWERSHELL_BAT_ARGS:"=\"%"
endlocal & powershell -NoLogo -NoProfile -Command "$_ = $input; Invoke-Expression $( '$input = $_; $_ = \"\"; $args = @( &{ $args } %POWERSHELL_BAT_ARGS% );' + [String]::Join( [char]10, $( Get-Content \"%~f0\" ) ) )"
goto :EOF
#>

# Create an instance of the Win32 API object to handle and manipulate windows
Add-Type @"
  using System;
  using System.Runtime.InteropServices;

  public class Win32 {
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
  }
"@

# Get a list of existing Explorer Windows
$previous_array = @()
$shell_object = New-Object -COM 'Shell.Application'

foreach($old_window in $shell_object.Windows())
{
    $previous_array += $old_window.HWND
}

# Open four more Explorer Windows in the current directory
explorer
explorer
explorer
explorer

# Pause for 1 second so that the windows have time to finish opening
sleep 1

# Get the list of new Explorer Windows
$new_array = @()
foreach($new_window in $shell_object.Windows())
{
    $new_array += $new_window.HWND
}

# Compare the two arrays and only process the new windows
$only_new = Compare-Object -ReferenceObject $previous_array -DifferenceObject $new_array -PassThru

# MoveWindow takes HWND value, X-position on screen, Y-position on screen, window width, and window height
# I've just hard-coded the values, adjust them to suit your needs
[Win32]::MoveWindow($only_new[0],0,0,960,540,$true)
[Win32]::MoveWindow($only_new[1],960,0,960,540,$true)
[Win32]::MoveWindow($only_new[2],0,540,960,540,$true)
[Win32]::MoveWindow($only_new[3],960,540,960,540,$true)