打开文件夹并最大化文件夹窗口

时间:2014-01-10 05:01:03

标签: powershell

我有以下简单的Powershell脚本:

ii E:\Source\Development\websites\example.com.au\root
ii E:\Source\Development\websites\example.com.au
ii E:\Source\Development\websites\example.com.au\css
ii E:\Source\Development\websites\example.com.au\database
ii E:\Source\Development\websites\example.com.au\js

但是,当文件夹窗口打开时,它们通常不会在全屏幕上最大化。我必须手动点击每个文件夹的窗口,然后在窗口菜单中选择“最大化”。对于比所示示例长得多的脚本(例如20加窗口),这很烦人。有谁知道使用PowerShell最大化这些文件夹窗口?

2 个答案:

答案 0 :(得分:1)

使用AppActivate方法,不要忘记发送Enter键以获得焦点,然后使用Alt Spacebar X(“%X”)进行最大化。

$folder = "C:\Temp"
ii $folder
Start-Sleep -m 100
[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
[Microsoft.VisualBasic.Interaction]::AppActivate("$folder")
Start-Sleep -m 100
[void][System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
[System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
[System.Windows.Forms.SendKeys]::SendWait("% X")

包裹一个循环,你已经完成了设置。

答案 1 :(得分:1)

您可以使用start-process而不是invoke-item,它可以控制窗口大小。您可以通过创建ii函数暂时覆盖别名来对脚本进行错误更改来实现,然后在完成后将其删除:

function ii { start-process explorer -WindowStyle Maximized -ArgumentList $args[0] }
ii E:\Source\Development\websites\example.com.au\root
ii E:\Source\Development\websites\example.com.au
ii E:\Source\Development\websites\example.com.au\css
ii E:\Source\Development\websites\example.com.au\database
ii E:\Source\Development\websites\example.com.au\js
Remove-Item function:ii